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 Villagers Ymiron v0.24.0
Villagers.dll
Decompiled 17 hours ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using Splatform; using TMPro; using UnityEngine; using UnityEngine.AI; using UnityEngine.Events; using UnityEngine.Rendering; using UnityEngine.UI; using Villagers.UI; using Villagers.Visuals; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyCompany("Villagers")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.24.0.0")] [assembly: AssemblyInformationalVersion("0.24.0")] [assembly: AssemblyProduct("Villagers")] [assembly: AssemblyTitle("Villagers")] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.24.0.0")] [module: UnverifiableCode] [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 Villagers { internal sealed class Aptitude { internal const int MaxLevel = 3; private static readonly JobKind[] Kinds = new JobKind[5] { JobKind.Woodcutter, JobKind.Stonecutter, JobKind.Farmer, JobKind.Stoker, JobKind.Caretaker }; internal JobKind Kind; internal int Level; internal string Name => LevelName(Level) + " " + TalentOf(Kind); internal float Bonus => (float)(Level * ModConfig.AptitudeBonus.Value) / 100f; internal string Description => $"+{Bonus * 100f:0}% work speed as {Workplace.WorkerTitleOf(Kind).ToLowerInvariant()}"; internal static string TalentOf(JobKind kind) { return kind switch { JobKind.Stonecutter => "Stonemason", JobKind.Farmer => "Green Thumb", JobKind.Stoker => "Smelter", JobKind.Caretaker => "Handyman", _ => "Woodsman", }; } internal static string LevelName(int level) { if (level < 3) { if (level != 2) { return "Novice"; } return "Skilled"; } return "Master"; } internal string Rich(bool withDescription) { return "<color=#FFC85C>" + Name + "</color>" + (withDescription ? ("<color=#B8AE9A> · " + Description + "</color>") : ""); } internal static Aptitude Roll() { float value = Random.value; return new Aptitude { Kind = Kinds[Random.Range(0, Kinds.Length)], Level = ((value < 0.55f) ? 1 : ((value < 0.88f) ? 2 : 3)) }; } internal string Pack() { return $"{(int)Kind}:{Level.ToString(CultureInfo.InvariantCulture)}"; } internal static Aptitude Parse(string text) { string[] array = (text ?? "").Split(':'); if (array.Length != 2 || !int.TryParse(array[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out var result) || !int.TryParse(array[1], NumberStyles.Integer, CultureInfo.InvariantCulture, out var result2) || Array.IndexOf(Kinds, (JobKind)result) < 0) { return null; } return new Aptitude { Kind = (JobKind)result, Level = Mathf.Clamp(result2, 1, 3) }; } } public class Armory : VillageStorage { internal override string GetHoverLines() { Inventory inventory = base.Inventory; int num = ((inventory != null) ? inventory.GetAllItems().Count(Gear.IsMeleeWeapon) : 0); int num2 = ((inventory != null) ? inventory.GetAllItems().Count((ItemData i) => Gear.IsArmor(i) || Gear.IsShield(i)) : 0); string text = ((num + num2 == 0) ? "<color=#FFB060>Put weapons, shields and armor inside for the villagers</color>" : $"Weapons: {num} · Armor and shields: {num2}"); return "<size=80%><color=#C8C8C8>" + text + "</color></size>"; } } [HarmonyPatch(typeof(Bed), "Awake")] internal static class Bed_Awake_Patch { private static void Postfix(Bed __instance) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Expected O, but got Unknown VillageWorld.Register((Component)__instance); } } [HarmonyPatch(typeof(Bed), "GetHoverText")] internal static class Bed_GetHoverText_Patch { private static void Postfix(Bed __instance, ref string __result) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Expected O, but got Unknown if (!VillageWorld.IsClaimedByPlayer(__instance)) { string holderName = VillageWorld.BedClaim.GetHolderName((Component)__instance); if (holderName.Length > 0) { __result = holderName + "'s bed <color=#C8C8C8>(villager)</color>\n" + __result; } } } } internal static class CaretakerTasks { internal const string RepairTag = "ymiron_repair"; private static HashSet<string> s_fuelNames; private static ZNetScene s_fuelScene; private static string s_ignoreParsed; private static HashSet<string> s_ignore = new HashSet<string>(); internal static float Radius => ModConfig.CaretakerRadius.Value; internal static bool IsTended(Fireplace fire) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Expected O, but got Unknown //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Expected O, but got Unknown //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Expected O, but got Unknown if ((Object)fire == (Object)null || (Object)fire.m_fuelItem == (Object)null || fire.m_infiniteFuel || !fire.m_canRefill || fire.m_maxFuel <= 0f) { return false; } Piece componentInParent = ((Component)fire).GetComponentInParent<Piece>(); ZDO val = ZdoOf((Component)fire); if ((Object)componentInParent == (Object)null || !componentInParent.IsPlacedByPlayer() || val == null) { return false; } if (fire.m_canTurnOff) { return val.GetInt(ZDOVars.s_state, 1) != 2; } return true; } internal static float Fuel(Fireplace fire) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Expected O, but got Unknown ZDO val = ZdoOf((Component)fire); if (val == null) { return 0f; } return val.GetFloat(ZDOVars.s_fuel, 0f); } internal static int Room(Fireplace fire) { return Mathf.Max(0, Mathf.FloorToInt(fire.m_maxFuel) - Mathf.CeilToInt(Fuel(fire))); } internal static float FuelShare(Fireplace fire) { return Fuel(fire) / Mathf.Max(1f, fire.m_maxFuel); } internal static string FuelName(Fireplace fire) { return ((Object)((Component)fire.m_fuelItem).gameObject).name; } internal static string DisplayName(Fireplace fire) { return Localization.instance.Localize(fire.m_name); } internal static List<Fireplace> Fires(Vector3 center) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) return VillageWorld.FindPieces<Fireplace>(center, Radius).Where(IsTended).ToList(); } internal static bool WantsFuel(Fireplace fire) { if (Room(fire) > 0) { return FuelShare(fire) * 100f <= (float)ModConfig.FuelBelow.Value; } return false; } internal static bool IsFuel(string prefabName) { //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Expected O, but got Unknown //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected O, but got Unknown //IL_0020: Expected O, but got Unknown //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Expected O, but got Unknown //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Expected O, but got Unknown //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Expected O, but got Unknown if (s_fuelNames == null || (Object)s_fuelScene != (Object)ZNetScene.instance) { s_fuelScene = ZNetScene.instance; s_fuelNames = new HashSet<string>(); if ((Object)ZNetScene.instance != (Object)null) { foreach (GameObject prefab in ZNetScene.instance.m_prefabs) { Fireplace val = (((Object)prefab != (Object)null) ? prefab.GetComponent<Fireplace>() : null); if ((Object)val != (Object)null && (Object)val.m_fuelItem != (Object)null) { s_fuelNames.Add(((Object)((Component)val.m_fuelItem).gameObject).name); } } } } if (prefabName != null) { return s_fuelNames.Contains(prefabName); } return false; } internal static float Health(WearNTear piece) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Expected O, but got Unknown ZDO val = ZdoOf((Component)piece); if (val == null) { return 1f; } return val.GetFloat(ZDOVars.s_health, piece.m_health) / Mathf.Max(1f, piece.m_health); } internal static bool IsDamaged(WearNTear piece) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Expected O, but got Unknown //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Expected O, but got Unknown if ((Object)piece == (Object)null || ZdoOf((Component)piece) == null || piece.m_health <= 0f) { return false; } Piece component = ((Component)piece).GetComponent<Piece>(); if ((Object)component != (Object)null && component.IsPlacedByPlayer()) { return Health(piece) * 100f < (float)ModConfig.RepairBelow.Value; } return false; } internal static List<WearNTear> Damaged(Vector3 center) { //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Expected O, but got Unknown //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) float radius = Radius; List<WearNTear> list = new List<WearNTear>(); foreach (WearNTear allInstance in WearNTear.GetAllInstances()) { if ((Object)allInstance != (Object)null) { Vector3 val = ((Component)allInstance).transform.position - center; if (((Vector3)(ref val)).sqrMagnitude <= radius * radius && IsDamaged(allInstance)) { list.Add(allInstance); } } } return list; } internal static bool IsWorn(ItemData item, float share) { if (item == null || !item.m_shared.m_useDurability) { return false; } float maxDurability = item.GetMaxDurability(); if (maxDurability > 0f) { return item.m_durability < maxDurability * share - 0.01f; } return false; } internal static List<ItemData> WornIn(VillageStorage storage) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown Inventory val = (((Object)storage != (Object)null) ? storage.Inventory : null); if (val == null) { return new List<ItemData>(); } float share = (float)ModConfig.ToolRepairBelow.Value / 100f; bool armory = storage is Armory; return (from i in val.GetAllItems() where (armory || Workplace.IsTool(i)) && IsWorn(i, share) select i).ToList(); } internal static IEnumerable<VillageStorage> ToolSources(Vector3 center) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) float radius = Mathf.Max(Radius, ModConfig.ToolRadius.Value); return (from w in VillageWorld.FindPieces<Workplace>(center, radius) where w.Kind != JobKind.Caretaker select w).Cast<VillageStorage>().Concat(VillageWorld.FindPieces<Armory>(center, radius)); } internal static List<ItemData> WornInWorkshop(Workplace workshop) { Inventory inventory = workshop.Inventory; return ((inventory != null) ? (from i in inventory.GetAllItems() where IsWorn(i, 1f) select i).ToList() : null) ?? new List<ItemData>(); } internal static bool IsTaggedForRepair(ItemData item) { return item?.m_customData.ContainsKey("ymiron_repair") ?? false; } internal static void Tag(ItemData item, ZDOID source) { item.m_customData["ymiron_repair"] = $"{((ZDOID)(ref source)).UserID}:{((ZDOID)(ref source)).ID}"; } internal static void Untag(ItemData item) { item?.m_customData.Remove("ymiron_repair"); } internal static ZDOID SourceOf(ItemData item) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) if (item == null || !item.m_customData.TryGetValue("ymiron_repair", out var value)) { return ZDOID.None; } string[] array = value.Split(':'); if (array.Length != 2 || !long.TryParse(array[0], out var result) || !uint.TryParse(array[1], out var result2)) { return ZDOID.None; } return new ZDOID(result, result2); } private static bool IsIgnored(string prefabName) { if (s_ignoreParsed != ModConfig.CollectIgnore.Value) { s_ignoreParsed = ModConfig.CollectIgnore.Value; s_ignore = new HashSet<string>(from n in (s_ignoreParsed ?? "").Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries) select n.Trim(), StringComparer.OrdinalIgnoreCase); } return s_ignore.Contains(prefabName); } internal static List<ItemDrop> Loose(Vector3 center, int itemMask) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: 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_002f: Expected O, but got Unknown //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Expected O, but got Unknown //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Expected O, but got Unknown //IL_014d: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Expected O, but got Unknown //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_01c6: Unknown result type (might be due to invalid IL or missing references) //IL_01d1: Expected O, but got Unknown List<ItemDrop> list = new List<ItemDrop>(); if (!ModConfig.CollectItems.Value || (Object)ZNet.instance == (Object)null) { return list; } List<ItemDrop> list2 = VillageWorld.FindComponents<ItemDrop>(center, Radius, itemMask).ToList(); if (list2.Count == 0) { return list; } DateTime time = ZNet.instance.GetTime(); List<Storehouse> source = VillageWorld.FindPieces<Storehouse>(center, Radius + 6f).ToList(); List<Vector3> source2 = StokerOutputs(center); List<(Vector3, MonsterAI)> source3 = (from c in Character.GetAllCharacters() where (Object)c != (Object)null && c.IsTamed() && Vector3.Distance(((Component)c).transform.position, center) < Radius + 15f select (position: ((Component)c).transform.position, ai: ((Component)c).GetComponent<MonsterAI>()) into t where (Object)t.ai != (Object)null && t.ai.m_consumeItems != null && t.ai.m_consumeItems.Count > 0 select t).ToList(); float num = (((Object)ZoneSystem.instance != (Object)null) ? ZoneSystem.instance.m_waterLevel : 30f); foreach (ItemDrop item in list2) { ZNetView val = (((Object)item != (Object)null) ? ((Component)item).GetComponent<ZNetView>() : null); if ((Object)val == (Object)null || !val.IsValid() || item.m_itemData == null) { continue; } ZDO zDO = val.GetZDO(); string name = Utils.GetPrefabName(((Component)item).gameObject); Vector3 position = ((Component)item).transform.position; ItemData itemData = item.m_itemData; if (!zDO.GetBool(ZDOVars.s_piece, false) && !((Object)((Component)item).GetComponent<Fish>() != (Object)null) && !(position.y < num + 0.2f) && !IsIgnored(name) && !Gear.IsMeleeWeapon(itemData) && !Gear.IsShield(itemData) && !Gear.IsArmor(itemData)) { long num2 = zDO.GetLong(ZDOVars.s_spawnTime, 0L); if ((num2 == 0L || !((time - new DateTime(num2)).TotalSeconds < (double)ModConfig.CollectDelay.Value)) && !source.Any((Storehouse s) => Utils.DistanceXZ(((Component)s).transform.position, position) < 6f) && !source2.Any((Vector3 o) => Vector3.Distance(o, position) < 3.5f) && !source3.Any<(Vector3, MonsterAI)>(((Vector3 position, MonsterAI ai) t) => Vector3.Distance(t.position, position) < 15f && t.ai.m_consumeItems.Any((ItemDrop c) => (Object)c != (Object)null && ((Object)((Component)c).gameObject).name == name))) { list.Add(item); } } } return list; } private static List<Vector3> StokerOutputs(Vector3 center) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Expected O, but got Unknown //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) List<Vector3> list = new List<Vector3>(); foreach (Workplace item in from w in VillageWorld.FindPieces<Workplace>(center, Radius + ModConfig.StokerRadius.Value) where w.Kind == JobKind.Stoker select w) { foreach (Smelter item2 in StokerStations.Around(((Component)item).transform.position)) { list.Add(((Object)item2.m_outputPoint != (Object)null) ? item2.m_outputPoint.position : ((Component)item2).transform.position); } } return list; } internal static ZDO ZdoOf(Component component) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Expected O, but got Unknown ZNetView val = (((Object)component != (Object)null) ? component.GetComponentInParent<ZNetView>() : null); if (!((Object)val != (Object)null) || !val.IsValid()) { return null; } return val.GetZDO(); } internal static ZDOID IdOf(Component component) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) return ZdoOf(component)?.m_uid ?? ZDOID.None; } } [HarmonyPatch(typeof(Chair), "IsInUse")] internal static class Chair_IsInUse_Patch { private static void Postfix(Chair __instance, ref bool __result) { __result |= Villager.IsSeatTaken(__instance.m_attachPoint); } } internal sealed class ChestPiece { private static readonly FieldInfo NamedPrefabsField = typeof(ZNetScene).GetField("m_namedPrefabs", BindingFlags.Instance | BindingFlags.NonPublic); private readonly string _prefabName; private readonly string _displayName; private readonly string _description; private readonly string _hammerAfter; private readonly Func<ConfigEntry<string>> _requirements; private readonly Func<int> _width; private readonly Func<int> _height; private readonly Action<ZNetScene, GameObject> _customize; private readonly bool _hideChest; private readonly bool _storage; private readonly bool _buildable; private GameObject _holder; internal GameObject Prefab { get; private set; } internal ChestPiece(string prefabName, string displayName, string description, string hammerAfter, Func<ConfigEntry<string>> requirements, Func<int> width, Func<int> height, Action<ZNetScene, GameObject> customize, bool hideChest = false, bool storage = true, bool buildable = true) { _hideChest = hideChest; _storage = storage; _buildable = buildable; _prefabName = prefabName; _displayName = displayName; _description = description; _hammerAfter = hammerAfter; _requirements = requirements; _width = width; _height = height; _customize = customize; } internal void Rebuild(ZNetScene scene) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Expected O, but got Unknown //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Expected O, but got Unknown //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Expected O, but got Unknown //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Expected O, but got Unknown //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Expected O, but got Unknown //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Expected O, but got Unknown GameObject prefab = scene.GetPrefab("piece_chest_wood"); if ((Object)prefab == (Object)null || (Object)prefab.GetComponent<Container>() == (Object)null) { VillagersPlugin.Log.LogError((object)("Base prefab 'piece_chest_wood' not found: '" + _displayName + "' will not be available.")); return; } if ((Object)_holder != (Object)null) { Object.Destroy((Object)_holder); } _holder = new GameObject(_prefabName + "_Holder"); _holder.SetActive(false); Object.DontDestroyOnLoad((Object)_holder); GameObject val = Object.Instantiate<GameObject>(prefab, _holder.transform, false); ((Object)val).name = _prefabName; Piece component = val.GetComponent<Piece>(); component.m_name = _displayName; component.m_description = _description; component.m_enabled = true; if (_storage) { Container component2 = val.GetComponent<Container>(); component2.m_name = _displayName; component2.m_width = _width(); component2.m_height = _height(); } else { StripChest(val); } List<Transform> chestParts = ((IEnumerable)val.transform).Cast<Transform>().ToList(); _customize(scene, val); if (_hideChest) { HideChest(chestParts); } RegisterInScene(scene, val); Prefab = val; VillagersPlugin.Log.LogInfo((object)("Prefab '" + _prefabName + "' created from 'piece_chest_wood'.")); } private static void HideChest(IEnumerable<Transform> chestParts) { //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Expected O, but got Unknown foreach (Transform chestPart in chestParts) { Renderer[] componentsInChildren = ((Component)chestPart).GetComponentsInChildren<Renderer>(true); for (int i = 0; i < componentsInChildren.Length; i++) { componentsInChildren[i].enabled = false; } Collider[] componentsInChildren2 = ((Component)chestPart).GetComponentsInChildren<Collider>(true); for (int j = 0; j < componentsInChildren2.Length; j++) { Object.DestroyImmediate((Object)componentsInChildren2[j]); } } } private static void StripChest(GameObject clone) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Expected O, but got Unknown //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Expected O, but got Unknown foreach (MonoBehaviour item in clone.GetComponents<MonoBehaviour>().Reverse()) { if (!(item is Piece) && !(item is ZNetView)) { Object.DestroyImmediate((Object)item); } } foreach (Transform item2 in ((IEnumerable)clone.transform).Cast<Transform>().ToList()) { Object.DestroyImmediate((Object)((Component)item2).gameObject); } } internal void RenderIcon() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Expected O, but got Unknown //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Expected O, but got Unknown Piece val = (((Object)Prefab != (Object)null) ? Prefab.GetComponent<Piece>() : null); Sprite val2 = (((Object)val != (Object)null) ? IconRenderer.Render(Prefab) : null); if ((Object)val2 != (Object)null) { val.m_icon = val2; VillagersPlugin.Log.LogInfo((object)("Icon for '" + _prefabName + "' rendered from the model.")); } } internal void TryFinalize() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Expected O, but got Unknown //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Expected O, but got Unknown //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Expected O, but got Unknown //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) if ((Object)Prefab == (Object)null) { return; } if (_storage) { Container component = Prefab.GetComponent<Container>(); if ((Object)(object)component != (Object)null) { component.m_width = _width(); component.m_height = _height(); } } ObjectDB instance = ObjectDB.instance; if ((Object)instance == (Object)null || instance.m_items.Count == 0) { return; } GameObject itemPrefab = instance.GetItemPrefab("Hammer"); PieceTable val = ((!((Object)itemPrefab != (Object)null)) ? null : itemPrefab.GetComponent<ItemDrop>()?.m_itemData?.m_shared?.m_buildPieces); if ((Object)val == (Object)null) { return; } Piece component2 = Prefab.GetComponent<Piece>(); component2.m_resources = ParseRequirements(instance, _requirements().Value, component2.m_resources); component2.m_usage = VillageCategory.Tag; val.m_pieces.RemoveAll((GameObject p) => (Object)p == (Object)null || ((Object)p != (Object)Prefab && ((Object)p).name == ((Object)Prefab).name)); if (!_buildable) { val.m_pieces.Remove(Prefab); } else { if (val.m_pieces.Contains(Prefab)) { return; } int num = val.m_pieces.FindIndex((GameObject p) => ((Object)p).name == _hammerAfter); if (num < 0) { num = val.m_pieces.FindIndex((GameObject p) => ((Object)p).name == "piece_chest_wood"); } if (num >= 0) { val.m_pieces.Insert(num + 1, Prefab); } else { val.m_pieces.Add(Prefab); } VillagersPlugin.Log.LogInfo((object)("'" + _prefabName + "' added to the hammer.")); } } private Requirement[] ParseRequirements(ObjectDB odb, string raw, Requirement[] fallback) { //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Expected O, but got Unknown //IL_00d2: 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_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Expected O, but got Unknown List<Requirement> list = new List<Requirement>(); string[] array = (raw ?? string.Empty).Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string text in array) { string[] array2 = text.Trim().Split(':'); if (array2.Length != 2 || !int.TryParse(array2[1].Trim(), out var result) || result <= 0) { VillagersPlugin.Log.LogWarning((object)("Invalid requirement '" + text + "'. Expected format Prefab:Amount.")); continue; } GameObject itemPrefab = odb.GetItemPrefab(array2[0].Trim()); ItemDrop val = (((Object)(object)itemPrefab != (Object)null) ? itemPrefab.GetComponent<ItemDrop>() : null); if ((Object)val == (Object)null) { VillagersPlugin.Log.LogWarning((object)("Item '" + array2[0].Trim() + "' not found in ObjectDB: skipped.")); continue; } list.Add(new Requirement { m_resItem = val, m_amount = result, m_recover = true }); } if (list.Count == 0) { VillagersPlugin.Log.LogWarning((object)("No valid requirements for '" + _displayName + "': keeping the chest recipe.")); return fallback ?? Array.Empty<Requirement>(); } return list.ToArray(); } private static void RegisterInScene(ZNetScene scene, GameObject prefab) { scene.m_prefabs.RemoveAll((GameObject p) => (Object)p == (Object)null || ((Object)p != (Object)prefab && ((Object)p).name == ((Object)prefab).name)); if (!scene.m_prefabs.Contains(prefab)) { scene.m_prefabs.Add(prefab); } if (NamedPrefabsField?.GetValue(scene) is Dictionary<int, GameObject> dictionary) { dictionary[StringExtensionMethods.GetStableHashCode(((Object)prefab).name)] = prefab; } else { VillagersPlugin.Log.LogError((object)("Cannot access ZNetScene.m_namedPrefabs: '" + ((Object)prefab).name + "' will not be buildable.")); } } } internal static class Commands { [Serializable] [CompilerGenerated] private sealed class _003C_003Ec { public static readonly _003C_003Ec _003C_003E9 = new _003C_003Ec(); public static ConsoleEvent _003C_003E9__2_0; public static ConsoleEvent _003C_003E9__2_1; public static ConsoleEvent _003C_003E9__2_2; public static ConsoleEvent _003C_003E9__2_3; public static ConsoleEvent _003C_003E9__2_4; internal void _003CRegister_003Eb__2_0(ConsoleEventArgs args) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Expected O, but got Unknown //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_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: 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_00d2: 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_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) //IL_00e9: 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_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if ((Object)localPlayer == (Object)null || (Object)VillagerFactory.Prefab == (Object)null) { args.Context.AddString("No player or villager prefab available."); return; } int num = 1; if (args.Args.Length > 1 && int.TryParse(args.Args[1], out var result)) { num = Mathf.Clamp(result, 1, 20); } for (int i = 0; i < num; i++) { Vector3 val = ((Component)localPlayer).transform.forward * 3f + Quaternion.Euler(0f, (float)i * 360f / (float)num, 0f) * Vector3.forward * ((num > 1) ? 1.5f : 0f); Vector3 val2 = ((Component)localPlayer).transform.position + val + Vector3.up; Quaternion val3 = Quaternion.LookRotation(-((Component)localPlayer).transform.forward); Object.Instantiate<GameObject>(VillagerFactory.Prefab, val2, val3); } args.Context.AddString($"Spawned {num} villager(s)."); } internal void _003CRegister_003Eb__2_1(ConsoleEventArgs args) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown //IL_0066: 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_0090: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Expected O, but got Unknown Player localPlayer = Player.m_localPlayer; if ((Object)localPlayer == (Object)null) { return; } float num = 20f; if (args.Args.Length > 1 && float.TryParse(args.Args[1], out var result)) { num = Mathf.Max(1f, result); } int num2 = 0; foreach (Villager item in Villager.All) { if (!(Vector3.Distance(((Component)item).transform.position, ((Component)localPlayer).transform.position) > num)) { VillagerAI component = ((Component)item).GetComponent<VillagerAI>(); string text = item.Describe() + (((Object)component != (Object)null) ? (", " + component.Describe()) : ""); args.Context.AddString(text); VillagersPlugin.Log.LogInfo((object)("[info] " + text)); num2++; } } if (num2 == 0) { args.Context.AddString($"No villagers within {num:0} m."); } } internal void _003CRegister_003Eb__2_2(ConsoleEventArgs args) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Expected O, but got Unknown //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Expected O, but got Unknown //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Expected O, but got Unknown //IL_00a6: Unknown result type (might be due to invalid IL or missing references) _003C_003Ec__DisplayClass2_0 CS_0024_003C_003E8__locals0 = new _003C_003Ec__DisplayClass2_0 { player = Player.m_localPlayer }; Villager villager = (((Object)CS_0024_003C_003E8__locals0.player != (Object)null) ? Villager.All.OrderBy((Villager v) => Vector3.Distance(((Component)v).transform.position, ((Component)CS_0024_003C_003E8__locals0.player).transform.position)).FirstOrDefault() : null); VillagerAI villagerAI = (((Object)villager != (Object)null) ? ((Component)villager).GetComponent<VillagerAI>() : null); if ((Object)villagerAI == (Object)null) { args.Context.AddString("No villager loaded."); return; } string text = ((Character)villager).GetHoverName() + ": " + villagerAI.DescribePathTo(((Component)CS_0024_003C_003E8__locals0.player).transform.position); args.Context.AddString(text); VillagersPlugin.Log.LogInfo((object)("[path] " + text)); } internal void _003CRegister_003Eb__2_3(ConsoleEventArgs args) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Expected O, but got Unknown //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Expected O, but got Unknown //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Expected O, but got Unknown //IL_00da: Unknown result type (might be due to invalid IL or missing references) _003C_003Ec__DisplayClass2_1 CS_0024_003C_003E8__locals0 = new _003C_003Ec__DisplayClass2_1 { player = Player.m_localPlayer }; Villager villager = (((Object)CS_0024_003C_003E8__locals0.player != (Object)null) ? Villager.All.OrderBy((Villager v) => Vector3.Distance(((Component)v).transform.position, ((Component)CS_0024_003C_003E8__locals0.player).transform.position)).FirstOrDefault() : null); VillagerAI villagerAI = (((Object)villager != (Object)null) ? ((Component)villager).GetComponent<VillagerAI>() : null); if ((Object)villagerAI == (Object)null) { args.Context.AddString("No villager loaded."); return; } float radius = 16f; if (args.Args.Length > 1 && float.TryParse(args.Args[1], out var result)) { radius = Mathf.Clamp(result, 4f, 25f); } string text = ((Character)villager).GetHoverName() + ": " + villagerAI.ShowWalkingMap(((Component)CS_0024_003C_003E8__locals0.player).transform.position, radius); args.Context.AddString(text); VillagersPlugin.Log.LogInfo((object)("[map] " + text)); } internal void _003CRegister_003Eb__2_4(ConsoleEventArgs args) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown //IL_006b: 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_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Expected O, but got Unknown Player localPlayer = Player.m_localPlayer; if ((Object)localPlayer == (Object)null) { return; } float num = 30f; if (args.Args.Length > 1 && float.TryParse(args.Args[1], out var result)) { num = Mathf.Max(1f, result); } int num2 = 0; foreach (Villager item in Villager.All.ToList()) { if (Vector3.Distance(((Component)item).transform.position, ((Component)localPlayer).transform.position) > num) { continue; } ZNetView component = ((Component)item).GetComponent<ZNetView>(); if ((Object)component != (Object)null && component.IsValid()) { component.ClaimOwnership(); if (item.HasBed()) { item.LoseBed("removed by command"); } if (item.HasJob()) { item.LoseJob("removed by command"); } component.Destroy(); num2++; } } args.Context.AddString($"Removed {num2} villager(s)."); } } [CompilerGenerated] private sealed class _003C_003Ec__DisplayClass2_0 { public Player player; internal float _003CRegister_003Eb__5(Villager v) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) return Vector3.Distance(((Component)v).transform.position, ((Component)player).transform.position); } } [CompilerGenerated] private sealed class _003C_003Ec__DisplayClass2_1 { public Player player; internal float _003CRegister_003Eb__6(Villager v) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) return Vector3.Distance(((Component)v).transform.position, ((Component)player).transform.position); } } [Serializable] [CompilerGenerated] private sealed class <>c { public static readonly <>c <>9 = new <>c(); public static ConsoleEvent <>9__5_0; public static ConsoleEvent <>9__5_1; public static ConsoleEvent <>9__5_2; public static ConsoleEvent <>9__5_4; public static ConsoleEvent <>9__5_6; internal void <Register>b__5_0(ConsoleEventArgs args) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Expected O, but got Unknown //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_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: 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_00d2: 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_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) //IL_00e9: 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_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if ((Object)localPlayer == (Object)null || (Object)VillagerFactory.Prefab == (Object)null) { args.Context.AddString("No player or villager prefab available."); return; } int num = 1; if (args.Args.Length > 1 && int.TryParse(args.Args[1], out var result)) { num = Mathf.Clamp(result, 1, 20); } for (int i = 0; i < num; i++) { Vector3 val = ((Component)localPlayer).transform.forward * 3f + Quaternion.Euler(0f, (float)i * 360f / (float)num, 0f) * Vector3.forward * ((num > 1) ? 1.5f : 0f); Vector3 val2 = ((Component)localPlayer).transform.position + val + Vector3.up; Quaternion val3 = Quaternion.LookRotation(-((Component)localPlayer).transform.forward); Object.Instantiate<GameObject>(VillagerFactory.Prefab, val2, val3); } args.Context.AddString($"Spawned {num} villager(s)."); } internal void <Register>b__5_1(ConsoleEventArgs args) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown //IL_0068: 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_0092: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Expected O, but got Unknown Player localPlayer = Player.m_localPlayer; if ((Object)localPlayer == (Object)null) { return; } float num = 20f; if (args.Args.Length > 1 && float.TryParse(args.Args[1], out var result)) { num = Mathf.Max(1f, result); } int num2 = 0; foreach (Villager item in Villager.All) { if (!(Vector3.Distance(((Component)item).transform.position, ((Component)localPlayer).transform.position) > num)) { VillagerAI component = ((Component)item).GetComponent<VillagerAI>(); string text = item.Describe() + (((Object)component != (Object)null) ? (", " + component.Describe()) : ""); args.Context.AddString(text); VillagersPlugin.Log.LogInfo((object)("[info] " + text)); num2++; } } if (num2 == 0) { args.Context.AddString($"No villagers within {num:0} m."); } } internal void <Register>b__5_2(ConsoleEventArgs args) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Expected O, but got Unknown //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Expected O, but got Unknown //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Expected O, but got Unknown //IL_0091: Unknown result type (might be due to invalid IL or missing references) <>c__DisplayClass5_0 CS$<>8__locals3 = new <>c__DisplayClass5_0 { player2 = Player.m_localPlayer }; Villager villager = (((Object)CS$<>8__locals3.player2 != (Object)null) ? Villager.All.OrderBy((Villager v) => Vector3.Distance(((Component)v).transform.position, ((Component)CS$<>8__locals3.player2).transform.position)).FirstOrDefault() : null); VillagerAI villagerAI = (((Object)villager != (Object)null) ? ((Component)villager).GetComponent<VillagerAI>() : null); if ((Object)villagerAI == (Object)null) { args.Context.AddString("No villager loaded."); return; } string text = ((Character)villager).GetHoverName() + ": " + villagerAI.DescribePathTo(((Component)CS$<>8__locals3.player2).transform.position); args.Context.AddString(text); VillagersPlugin.Log.LogInfo((object)("[path] " + text)); } internal void <Register>b__5_4(ConsoleEventArgs args) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Expected O, but got Unknown //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Expected O, but got Unknown //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Expected O, but got Unknown //IL_00c5: Unknown result type (might be due to invalid IL or missing references) <>c__DisplayClass5_1 CS$<>8__locals3 = new <>c__DisplayClass5_1 { player = Player.m_localPlayer }; Villager villager = (((Object)CS$<>8__locals3.player != (Object)null) ? Villager.All.OrderBy((Villager v) => Vector3.Distance(((Component)v).transform.position, ((Component)CS$<>8__locals3.player).transform.position)).FirstOrDefault() : null); VillagerAI villagerAI = (((Object)villager != (Object)null) ? ((Component)villager).GetComponent<VillagerAI>() : null); if ((Object)villagerAI == (Object)null) { args.Context.AddString("No villager loaded."); return; } float radius = 16f; if (args.Args.Length > 1 && float.TryParse(args.Args[1], out var result)) { radius = Mathf.Clamp(result, 4f, 25f); } string text = ((Character)villager).GetHoverName() + ": " + villagerAI.ShowWalkingMap(((Component)CS$<>8__locals3.player).transform.position, radius); args.Context.AddString(text); VillagersPlugin.Log.LogInfo((object)("[map] " + text)); } internal void <Register>b__5_6(ConsoleEventArgs args) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown //IL_006d: 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_0090: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Expected O, but got Unknown Player localPlayer = Player.m_localPlayer; if ((Object)localPlayer == (Object)null) { return; } float num = 30f; if (args.Args.Length > 1 && float.TryParse(args.Args[1], out var result)) { num = Mathf.Max(1f, result); } int num2 = 0; foreach (Villager item in Villager.All.ToList()) { if (Vector3.Distance(((Component)item).transform.position, ((Component)localPlayer).transform.position) > num) { continue; } ZNetView component = ((Component)item).GetComponent<ZNetView>(); if ((Object)component != (Object)null && component.IsValid()) { component.ClaimOwnership(); if (item.HasBed()) { item.LoseBed("removed by command"); } if (item.HasJob()) { item.LoseJob("removed by command"); } component.Destroy(); num2++; } } args.Context.AddString($"Removed {num2} villager(s)."); } } [CompilerGenerated] private sealed class <>c__DisplayClass5_0 { public Player player2; internal float <Register>b__3(Villager v) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) return Vector3.Distance(((Component)v).transform.position, ((Component)player2).transform.position); } } [CompilerGenerated] private sealed class <>c__DisplayClass5_1 { public Player player; internal float <Register>b__5(Villager v) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) return Vector3.Distance(((Component)v).transform.position, ((Component)player).transform.position); } } private const int MaxSpawnCount = 20; private static bool _registered; internal static void Register() { //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Expected O, but got Unknown //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Expected O, but got Unknown //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Expected O, but got Unknown //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Expected O, but got Unknown //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Expected O, but got Unknown //IL_0144: 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_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Expected O, but got Unknown //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_019c: Expected O, but got Unknown //IL_0197: 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_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Expected O, but got Unknown //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_0174: Expected O, but got Unknown if (_registered) { return; } _registered = true; object obj = _003C_003Ec._003C_003E9__2_0; if (obj == null) { object obj2 = <>c.<>9__5_0; if (obj2 == null) { ConsoleEvent val = delegate(ConsoleEventArgs args) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Expected O, but got Unknown //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_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: 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_00d2: 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_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) //IL_00e9: 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_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if ((Object)localPlayer == (Object)null || (Object)VillagerFactory.Prefab == (Object)null) { args.Context.AddString("No player or villager prefab available."); } else { int num = 1; if (args.Args.Length > 1 && int.TryParse(args.Args[1], out var result)) { num = Mathf.Clamp(result, 1, 20); } for (int i = 0; i < num; i++) { Vector3 val6 = ((Component)localPlayer).transform.forward * 3f + Quaternion.Euler(0f, (float)i * 360f / (float)num, 0f) * Vector3.forward * ((num > 1) ? 1.5f : 0f); Vector3 val7 = ((Component)localPlayer).transform.position + val6 + Vector3.up; Quaternion val8 = Quaternion.LookRotation(-((Component)localPlayer).transform.forward); Object.Instantiate<GameObject>(VillagerFactory.Prefab, val7, val8); } args.Context.AddString($"Spawned {num} villager(s)."); } }; <>c.<>9__5_0 = val; obj2 = (object)val; } _003C_003Ec._003C_003E9__2_0 = (ConsoleEvent)obj2; obj = obj2; } new ConsoleCommand("villager", "[count] - spawns villagers in front of you (Villagers-Ymiron)", (ConsoleEvent)obj, true, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); object obj3 = _003C_003Ec._003C_003E9__2_1; if (obj3 == null) { object obj4 = <>c.<>9__5_1; if (obj4 == null) { ConsoleEvent val2 = delegate(ConsoleEventArgs args) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown //IL_0068: 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_0092: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Expected O, but got Unknown Player localPlayer = Player.m_localPlayer; if (!((Object)localPlayer == (Object)null)) { float num = 20f; if (args.Args.Length > 1 && float.TryParse(args.Args[1], out var result)) { num = Mathf.Max(1f, result); } int num2 = 0; foreach (Villager item in Villager.All) { if (!(Vector3.Distance(((Component)item).transform.position, ((Component)localPlayer).transform.position) > num)) { VillagerAI component = ((Component)item).GetComponent<VillagerAI>(); string text = item.Describe() + (((Object)component != (Object)null) ? (", " + component.Describe()) : ""); args.Context.AddString(text); VillagersPlugin.Log.LogInfo((object)("[info] " + text)); num2++; } } if (num2 == 0) { args.Context.AddString($"No villagers within {num:0} m."); } } }; <>c.<>9__5_1 = val2; obj4 = (object)val2; } _003C_003Ec._003C_003E9__2_1 = (ConsoleEvent)obj4; obj3 = obj4; } new ConsoleCommand("villager_info", "[radius] - shows what the villagers around you are doing (Villagers-Ymiron)", (ConsoleEvent)obj3, true, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); object obj5 = _003C_003Ec._003C_003E9__2_2; if (obj5 == null) { object obj6 = <>c.<>9__5_2; if (obj6 == null) { ConsoleEvent val3 = delegate(ConsoleEventArgs args) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Expected O, but got Unknown //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Expected O, but got Unknown //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Expected O, but got Unknown //IL_0091: Unknown result type (might be due to invalid IL or missing references) Player player2 = Player.m_localPlayer; Villager villager = (((Object)player2 != (Object)null) ? Villager.All.OrderBy((Villager v) => Vector3.Distance(((Component)v).transform.position, ((Component)player2).transform.position)).FirstOrDefault() : null); VillagerAI villagerAI = (((Object)villager != (Object)null) ? ((Component)villager).GetComponent<VillagerAI>() : null); if ((Object)villagerAI == (Object)null) { args.Context.AddString("No villager loaded."); } else { string text = ((Character)villager).GetHoverName() + ": " + villagerAI.DescribePathTo(((Component)player2).transform.position); args.Context.AddString(text); VillagersPlugin.Log.LogInfo((object)("[path] " + text)); } }; <>c.<>9__5_2 = val3; obj6 = (object)val3; } _003C_003Ec._003C_003E9__2_2 = (ConsoleEvent)obj6; obj5 = obj6; } new ConsoleCommand("villager_path", "- can the closest villager walk to where you stand? (Villagers-Ymiron)", (ConsoleEvent)obj5, true, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); object obj7 = _003C_003Ec._003C_003E9__2_3; if (obj7 == null) { object obj8 = <>c.<>9__5_4; if (obj8 == null) { ConsoleEvent val4 = delegate(ConsoleEventArgs args) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Expected O, but got Unknown //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Expected O, but got Unknown //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Expected O, but got Unknown //IL_00c5: Unknown result type (might be due to invalid IL or missing references) Player player = Player.m_localPlayer; Villager villager = (((Object)player != (Object)null) ? Villager.All.OrderBy((Villager v) => Vector3.Distance(((Component)v).transform.position, ((Component)player).transform.position)).FirstOrDefault() : null); VillagerAI villagerAI = (((Object)villager != (Object)null) ? ((Component)villager).GetComponent<VillagerAI>() : null); if ((Object)villagerAI == (Object)null) { args.Context.AddString("No villager loaded."); } else { float radius = 16f; if (args.Args.Length > 1 && float.TryParse(args.Args[1], out var result)) { radius = Mathf.Clamp(result, 4f, 25f); } string text = ((Character)villager).GetHoverName() + ": " + villagerAI.ShowWalkingMap(((Component)player).transform.position, radius); args.Context.AddString(text); VillagersPlugin.Log.LogInfo((object)("[map] " + text)); } }; <>c.<>9__5_4 = val4; obj8 = (object)val4; } _003C_003Ec._003C_003E9__2_3 = (ConsoleEvent)obj8; obj7 = obj8; } new ConsoleCommand("villager_map", "[radius] - shows where the closest villager can walk (Villagers-Ymiron)", (ConsoleEvent)obj7, true, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); object obj9 = _003C_003Ec._003C_003E9__2_4; if (obj9 == null) { object obj10 = <>c.<>9__5_6; if (obj10 == null) { ConsoleEvent val5 = delegate(ConsoleEventArgs args) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown //IL_006d: 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_0090: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Expected O, but got Unknown Player localPlayer = Player.m_localPlayer; if (!((Object)localPlayer == (Object)null)) { float num = 30f; if (args.Args.Length > 1 && float.TryParse(args.Args[1], out var result)) { num = Mathf.Max(1f, result); } int num2 = 0; foreach (Villager item2 in Villager.All.ToList()) { if (!(Vector3.Distance(((Component)item2).transform.position, ((Component)localPlayer).transform.position) > num)) { ZNetView component = ((Component)item2).GetComponent<ZNetView>(); if ((Object)component != (Object)null && component.IsValid()) { component.ClaimOwnership(); if (item2.HasBed()) { item2.LoseBed("removed by command"); } if (item2.HasJob()) { item2.LoseJob("removed by command"); } component.Destroy(); num2++; } } } args.Context.AddString($"Removed {num2} villager(s)."); } }; <>c.<>9__5_6 = val5; obj10 = (object)val5; } _003C_003Ec._003C_003E9__2_4 = (ConsoleEvent)obj10; obj9 = obj10; } new ConsoleCommand("villager_clear", "[radius] - removes the villagers around you (Villagers-Ymiron)", (ConsoleEvent)obj9, true, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); } } internal class ConfigSync : MonoBehaviour { private const string RpcRequest = "ymiron_villagers_config_request"; private const string RpcValues = "ymiron_villagers_config"; private const float RequestInterval = 10f; private const int MaxRequests = 6; private static ConfigSync s_instance; private ZPackage _serverValues; private float _requestTimer = 3f; private int _requests; private bool _registered; internal static bool Synced { get { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown if ((Object)s_instance != (Object)null) { return s_instance._serverValues != null; } return false; } } private void Awake() { s_instance = this; } private void Update() { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown if (ZRoutedRpc.instance == null || (Object)ZNet.instance == (Object)null) { return; } if (!_registered) { _registered = true; ZRoutedRpc.instance.Register("ymiron_villagers_config_request", (Action<long>)RPC_Request); ZRoutedRpc.instance.Register<ZPackage>("ymiron_villagers_config", (Action<long, ZPackage>)RPC_Values); } if (ZNet.instance.IsServer() || _serverValues != null || _requests >= 6 || ZNet.instance.GetServerPeer() == null) { return; } _requestTimer -= Time.deltaTime; if (!(_requestTimer > 0f)) { _requestTimer = 10f; _requests++; ZRoutedRpc.instance.InvokeRoutedRPC("ymiron_villagers_config_request", Array.Empty<object>()); if (_requests == 6) { VillagersPlugin.Log.LogWarning((object)"The server does not send its Villagers-Ymiron settings (no mod there?): each player uses their own config file."); } } } private static void RPC_Request(long sender) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown if (!((Object)ZNet.instance == (Object)null) && ZNet.instance.IsServer()) { ZRoutedRpc.instance.InvokeRoutedRPC(sender, "ymiron_villagers_config", new object[1] { Pack() }); } } internal static void ServerConfigChanged() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown if ((Object)ZNet.instance != (Object)null && ZNet.instance.IsServer() && ZRoutedRpc.instance != null) { ZRoutedRpc.instance.InvokeRoutedRPC(0L, "ymiron_villagers_config", new object[1] { Pack() }); } } private static ZPackage Pack() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown ZPackage val = new ZPackage(); List<ConfigDefinition> list = ModConfig.File.Keys.Where((ConfigDefinition d) => !ModConfig.IsLocalOnly(d)).ToList(); val.Write(list.Count); foreach (ConfigDefinition item in list) { val.Write(item.Section); val.Write(item.Key); val.Write(ModConfig.File[item].GetSerializedValue()); } return val; } private void RPC_Values(long sender, ZPackage package) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Expected O, but got Unknown if (!((Object)ZNet.instance == (Object)null) && !ZNet.instance.IsServer()) { _serverValues = new ZPackage(package.GetArray()); int num = Apply(_serverValues); VillagePieces.TryFinalize(); VillagersPlugin.Log.LogInfo((object)$"Villagers-Ymiron settings received from the server: {num} applied (your file is unchanged)."); } } internal static void Reapply() { if (Synced) { Apply(s_instance._serverValues); } } private static int Apply(ZPackage package) { package.SetPos(0); ConfigFile file = ModConfig.File; file.SaveOnConfigSet = false; int num = 0; try { int num2 = package.ReadInt(); for (int i = 0; i < num2; i++) { string section = package.ReadString(); string key = package.ReadString(); string text = package.ReadString(); ConfigDefinition val = ((IEnumerable<ConfigDefinition>)file.Keys).FirstOrDefault((Func<ConfigDefinition, bool>)((ConfigDefinition d) => d.Section == section && d.Key == key)); if (!(val == (ConfigDefinition)null) && !ModConfig.IsLocalOnly(val)) { ConfigEntryBase val2 = file[val]; if (val2.GetSerializedValue() != text) { val2.SetSerializedValue(text); } num++; } } } catch (Exception ex) { VillagersPlugin.Log.LogWarning((object)("Villagers-Ymiron settings from the server not fully applied: " + ex.Message)); } return num; } private void OnDestroy() { //IL_0005: 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_0015: Expected O, but got Unknown //IL_0015: Expected O, but got Unknown if ((Object)s_instance == (Object)this) { s_instance = null; } if (_serverValues != null) { _serverValues = null; ModConfig.File.SaveOnConfigSet = true; ModConfig.File.Reload(); VillagePieces.TryFinalize(); VillagersPlugin.Log.LogInfo((object)"Left the server: Villagers-Ymiron uses your own settings again."); } } } [HarmonyPatch(typeof(Container), "GetHoverText")] internal static class Container_GetHoverText_Patch { private static void Postfix(Container __instance, ref string __result) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Expected O, but got Unknown VillageStorage component = ((Component)__instance).GetComponent<VillageStorage>(); if ((Object)component != (Object)null) { __result = __result + "\n" + component.GetHoverLines(); } } } [HarmonyPatch(typeof(Container), "Interact")] internal static class Container_Interact_Patch { private static bool Prefix(Container __instance, Humanoid character, bool hold, bool alt, ref bool __result) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Expected O, but got Unknown //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Expected O, but got Unknown //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Expected O, but got Unknown //IL_0034: Expected O, but got Unknown //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Expected O, but got Unknown //IL_0077: Expected O, but got Unknown if (!alt || hold) { return true; } Pantry component = ((Component)__instance).GetComponent<Pantry>(); if ((Object)component != (Object)null) { if ((Object)character == (Object)Player.m_localPlayer) { WorkPanel.Open(component); } __result = true; return false; } Workplace component2 = ((Component)__instance).GetComponent<Workplace>(); if ((Object)component2 == (Object)null || component2.Kind == JobKind.Caretaker) { return true; } if ((Object)character == (Object)Player.m_localPlayer) { WorkPanel.Open(component2); } __result = true; return false; } } [HarmonyPatch(typeof(Door), "Awake")] internal static class Door_Awake_Patch { private static void Postfix(Door __instance) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Expected O, but got Unknown VillageWorld.Register((Component)__instance); } } internal static class DrawerBridge { private const BindingFlags Any = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; private static bool s_searched; private static FieldInfo s_all; private static PropertyInfo s_isValid; private static PropertyInfo s_slots; private static MethodInfo s_getItem; private static MethodInfo s_getData; private static MethodInfo s_holds; private static MethodInfo s_roomFor; private static MethodInfo s_add; private static MethodInfo s_canStore; private static MethodInfo s_dataKey; internal static bool Available { get { if (!s_searched) { s_searched = true; Bind(); } return s_add != null; } } private static void Bind() { try { Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetType("ItemDrawers.Drawer") != null); if (assembly == null) { VillagersPlugin.Log.LogInfo((object)"ItemDrawers-Ymiron not installed: the caretaker does not sort into drawers."); return; } Type type = assembly.GetType("ItemDrawers.Drawer"); Type? type2 = assembly.GetType("ItemDrawers.ItemInfo"); s_all = type.GetField("All", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); s_isValid = type.GetProperty("IsValid", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); s_slots = type.GetProperty("Slots", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); s_getItem = type.GetMethod("GetItem", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); s_getData = type.GetMethod("GetData", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); s_holds = type.GetMethod("Holds", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); s_roomFor = type.GetMethod("RoomFor", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); MethodInfo method = type.GetMethod("Add", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); s_canStore = type2?.GetMethod("CanStore", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); s_dataKey = type2?.GetMethod("DataKey", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if (s_all == null || s_isValid == null || s_slots == null || s_getItem == null || s_getData == null || s_holds == null || s_roomFor == null || method == null || s_canStore == null || s_dataKey == null) { VillagersPlugin.Log.LogWarning((object)"ItemDrawers-Ymiron found, but not the version expected: the caretaker does not sort into drawers."); return; } s_add = method; VillagersPlugin.Log.LogInfo((object)"ItemDrawers-Ymiron found: the caretaker sorts the storehouse into the drawers in the evening."); } catch (Exception ex) { VillagersPlugin.Log.LogWarning((object)("ItemDrawers-Ymiron could not be read: " + ex.Message)); s_add = null; } } internal static List<Component> DrawersAround(Vector3 center, float radius) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: 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_0056: Expected O, but got Unknown //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Expected O, but got Unknown //IL_0089: 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) List<Component> list = new List<Component>(); if (!Available || !(s_all.GetValue(null) is IList list2)) { return list; } foreach (object item in list2) { Component val = (Component)((item is Component) ? item : null); if ((Object)(object)val != (Object)null && (Object)val != (Object)null && (bool)s_isValid.GetValue(val) && Vector3.Distance(val.transform.position, center) <= radius) { list.Add(val); } } return list.OrderBy((Component d) => Vector3.Distance(d.transform.position, center)).ToList(); } internal static int SlotCount(Component drawer) { return (int)s_slots.GetValue(drawer); } internal static bool CanStore(ItemData item, out string data) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Expected O, but got Unknown data = ""; if (!Available || item == null || (Object)item.m_dropPrefab == (Object)null || !(bool)s_canStore.Invoke(null, new object[1] { item })) { return false; } data = ((string)s_dataKey.Invoke(null, new object[1] { item })) ?? ""; return true; } internal static int RoomIn(Component drawer, string prefab, string data) { int num = 0; for (int i = 0; i < SlotCount(drawer); i++) { if ((bool)s_holds.Invoke(drawer, new object[3] { i, prefab, data })) { num += (int)s_roomFor.Invoke(drawer, new object[3] { i, prefab, data }); } } return num; } internal static int AddTo(Component drawer, string prefab, string data, int amount) { int num = 0; for (int i = 0; i < SlotCount(drawer); i++) { if (num >= amount) { break; } if ((bool)s_holds.Invoke(drawer, new object[3] { i, prefab, data })) { num += (int)s_add.Invoke(drawer, new object[4] { i, prefab, data, amount - num }); } } return num; } internal static int RoomIn(IEnumerable<Component> drawers, string prefab, string data) { return drawers.Sum((Component d) => RoomIn(d, prefab, data)); } } internal static class FarmCrops { internal sealed class Crop { internal GameObject Sapling; internal Plant Plant; internal Piece Piece; internal string SeedName; internal int SeedAmount; internal HashSet<string> Grown = new HashSet<string>(); internal string DisplayName => Localization.instance.Localize(Piece.m_name); internal string SeedDisplayName { get { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Expected O, but got Unknown ObjectDB instance = ObjectDB.instance; GameObject val = (((Object)instance != (Object)null) ? instance.GetItemPrefab(SeedName) : null); string text = ((!((Object)val != (Object)null)) ? null : val.GetComponent<ItemDrop>()?.m_itemData.m_shared.m_name); return Localization.instance.Localize(text ?? SeedName); } } } private static ObjectDB s_builtFor; private static readonly List<Crop> s_crops = new List<Crop>(); private static readonly Dictionary<string, Crop> s_byGrown = new Dictionary<string, Crop>(); private static readonly HashSet<string> s_seedNames = new HashSet<string>(); private static readonly HashSet<string> s_produceNames = new HashSet<string>(); private static readonly HashSet<string> s_selfSown = new HashSet<string>(); private static float s_widest = 0.5f; private static int s_roofMask; private static int s_spaceMask; private static readonly Collider[] s_hits = (Collider[])(object)new Collider[64]; internal static IReadOnlyList<Crop> All { get { Refresh(); return s_crops; } } internal static Crop Find(string saplingName) { if (!string.IsNullOrEmpty(saplingName)) { return All.FirstOrDefault((Crop c) => ((Object)c.Sapling).name == saplingName); } return null; } private static void Refresh() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Expected O, but got Unknown //IL_0029: Expected O, but got Unknown //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Expected O, but got Unknown //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Expected O, but got Unknown //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Expected O, but got Unknown //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Expected O, but got Unknown //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Expected O, but got Unknown //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Expected O, but got Unknown //IL_01af: Unknown result type (might be due to invalid IL or missing references) //IL_01ba: Expected O, but got Unknown //IL_027a: Unknown result type (might be due to invalid IL or missing references) //IL_0285: Expected O, but got Unknown //IL_028e: Unknown result type (might be due to invalid IL or missing references) //IL_0299: Expected O, but got Unknown ObjectDB instance = ObjectDB.instance; if ((Object)instance == (Object)null || (Object)instance == (Object)s_builtFor || instance.m_items.Count == 0) { return; } s_builtFor = instance; s_crops.Clear(); s_byGrown.Clear(); s_seedNames.Clear(); s_produceNames.Clear(); s_selfSown.Clear(); HashSet<string> hashSet = new HashSet<string>(); foreach (GameObject item in instance.m_items) { PieceTable val = ((!((Object)item != (Object)null)) ? null : item.GetComponent<ItemDrop>()?.m_itemData?.m_shared?.m_buildPieces); if ((Object)val == (Object)null) { continue; } foreach (GameObject piece in val.m_pieces) { Plant val2 = (((Object)piece != (Object)null) ? piece.GetComponent<Plant>() : null); Piece val3 = (((Object)piece != (Object)null) ? piece.GetComponent<Piece>() : null); if ((Object)val2 == (Object)null || (Object)val3 == (Object)null || !val2.m_needCultivatedGround || val2.m_attachDistance > 0f || val3.m_resources == null || val3.m_resources.Length == 0 || !hashSet.Add(((Object)piece).name)) { continue; } Requirement val4 = val3.m_resources[0]; if ((Object)val4.m_resItem == (Object)null) { continue; } Crop crop = new Crop { Sapling = piece, Plant = val2, Piece = val3, SeedName = ((Object)((Component)val4.m_resItem).gameObject).name, SeedAmount = Mathf.Max(1, val4.m_amount) }; foreach (GameObject item2 in val2.m_grownPrefabs.Where((GameObject g) => (Object)g != (Object)null)) { crop.Grown.Add(((Object)item2).name); s_byGrown[((Object)item2).name] = crop; Pickable component = item2.GetComponent<Pickable>(); if ((Object)component != (Object)null && (Object)component.m_itemPrefab != (Object)null) { s_produceNames.Add(((Object)component.m_itemPrefab).name); if (((Object)component.m_itemPrefab).name == crop.SeedName) { s_selfSown.Add(crop.SeedName); } } } if (crop.Grown.Count != 0) { s_crops.Add(crop); s_seedNames.Add(crop.SeedName); s_produceNames.Add(crop.SeedName); } } } s_widest = ((s_crops.Count > 0) ? s_crops.Max((Crop c) => c.Plant.m_growRadius) : 0.5f); VillagersPlugin.Log.LogInfo((object)("Farm crops known: " + string.Join(", ", s_crops.Select((Crop c) => $"{((Object)c.Sapling).name} ({c.SeedName}, every {StepOf(c):0.00} m)")))); } internal static float StepOf(Crop crop) { return Mathf.Clamp(crop.Plant.m_growRadius * 2f + 0.05f, 0.5f, 3f); } internal static Crop CropOf(Pickable pickable) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown Refresh(); if (!((Object)pickable != (Object)null) || !s_byGrown.TryGetValue(Utils.GetPrefabName(((Component)pickable).gameObject), out var value)) { return null; } return value; } internal static Crop CropOf(Plant plant) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown Refresh(); if ((Object)plant == (Object)null) { return null; } string name = Utils.GetPrefabName(((Component)plant).gameObject); return s_crops.FirstOrDefault((Crop c) => ((Object)c.Sapling).name == name); } internal static IEnumerable<Crop> SownFrom(string seedName) { return All.Where((Crop c) => c.SeedName == seedName); } internal static string NameOf(ItemData item) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown if (!((Object)(item?.m_dropPrefab) != (Object)null)) { return null; } return ((Object)item.m_dropPrefab).name; } internal static bool IsSeed(ItemData item) { Refresh(); string text = NameOf(item); if (text != null) { return s_seedNames.Contains(text); } return false; } internal static bool IsPureSeed(ItemData item) { Refresh(); string text = NameOf(item); if (text != null && s_seedNames.Contains(text) && !s_selfSown.Contains(text)) { return !Pantry.IsFood(item); } return false; } internal static bool IsProduce(ItemData item) { Refresh(); string text = NameOf(item); if (text != null) { return s_produceNames.Contains(text); } return false; } internal static bool CanGrowAt(Crop crop, Vector3 position) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Expected O, but got Unknown //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0028: 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_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Invalid comparison between Unknown and I4 //IL_0078: 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_006d: Invalid comparison between Unknown and I4 //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Invalid comparison between Unknown and I4 Heightmap val = Heightmap.FindHeightmap(position); if ((Object)val == (Object)null || !val.IsCultivated(position)) { return false; } Biome biome = val.GetBiome(position, 0.02f, false); if ((biome & crop.Plant.m_biome) == 0) { return false; } bool flag = ShieldGenerator.IsInsideShield(position); if (!crop.Plant.m_tolerateHeat && (int)biome == 32 && !flag) { return false; } if (!crop.Plant.m_tolerateCold && ((int)biome == 64 || (int)biome == 4) && !flag) { return false; } return !HasRoof(position); } private static bool HasRoof(Vector3 position) { //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) if (s_roofMask == 0) { s_roofMask = LayerMask.GetMask(new string[3] { "Default", "static_solid", "piece" }); } return Physics.Raycast(position, Vector3.up, 100f, s_roofMask); } internal static bool HasRoom(Crop crop, Vector3 position) { //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Expected O, but got Unknown //IL_00a3: 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_00bf: 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_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: 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_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Expected O, but got Unknown //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) if (s_spaceMask == 0) { s_spaceMask = LayerMask.GetMask(new string[5] { "Default", "static_solid", "Default_small", "piece", "piece_nonsolid" }); } float num = Mathf.Max(crop.Plant.m_growRadius, s_widest) + 0.2f; int num2 = Physics.OverlapSphereNonAlloc(position, num, s_hits, s_spaceMask); for (int i = 0; i < num2; i++) { Collider val = s_hits[i]; MeshCollider val2 = (MeshCollider)((val is MeshCollider) ? val : null); Vector3 val3; if ((Object)(object)val2 == (Object)null || val2.convex) { val3 = val.ClosestPoint(position); } else { Bounds bounds = val.bounds; val3 = ((Bounds)(ref bounds)).ClosestPoint(position); } if (Vector3.Distance(val3, position) < crop.Plant.m_growRadius) { return false; } Plant componentInParent = ((Component)val).GetComponentInParent<Plant>(); if ((Object)componentInParent != (Object)null && Utils.DistanceXZ(((Component)componentInParent).transform.position, position) < componentInParent.m_growRadius + 0.15f) { return false; } } return true; } internal static bool IsFree(Vector3 position, float radius) { //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_004a: 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) if (s_spaceMask == 0) { s_spaceMask = LayerMask.GetMask(new string[5] { "Default", "static_solid", "Default_small", "piece", "piece_nonsolid" }); } return !Physics.CheckSphere(position + Vector3.up * 0.15f, radius, s_spaceMask); } } [HarmonyPatch(typeof(Fireplace), "Awake")] internal static class Fireplace_Awake_Patch { private static void Postfix(Fireplace __instance) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Expected O, but got Unknown VillageWorld.Register((Component)__instance); } } [HarmonyPatch(typeof(Game), "Start")] internal static class Game_Start_Patch { private static void Postfix(Game __instance) { ((Component)__instance).gameObject.AddComponent<VillagersNetwork>(); ((Component)__instance).gameObject.AddComponent<VillagerMapPins>(); ((Component)__instance).gameObject.AddComponent<PathMarkerOverlay>(); ((Component)__instance).gameObject.AddComponent<ConfigSync>(); ((Component)__instance).gameObject.AddComponent<VillagerPanel>(); ((Component)__instance).gameObject.AddComponent<RecruitPanel>(); ((Component)__instance).gameObject.AddComponent<WorkPanel>(); ((Component)__instance).gameObject.AddComponent<VillageHallPanel>(); VillagePieces.RenderIcons(); } } internal static class Gear { internal const string ToolTag = "ymiron_tool"; internal const string OutfitTag = "ymiron_outfit"; private static readonly HashSet<SkillType> MeleeSkills = new HashSet<SkillType> { (SkillType)1, (SkillType)2, (SkillType)3, (SkillType)4, (SkillType)5, (SkillType)7 }; internal static bool IsUsable(ItemData item) { if (item.m_shared.m_useDurability) { return item.m_durability > 0f; } return true; } internal static bool IsMeleeWeapon(ItemData item) { //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_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Invalid comparison between Unknown and I4 //IL_0025: 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_0013: Invalid comparison between Unknown and I4 //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Invalid comparison between Unknown and I4 ItemType itemType = item.m_shared.m_itemType; if ((int)itemType == 3 || (int)itemType == 14 || (int)itemType == 22) { return MeleeSkills.Contains(item.m_shared.m_skillType); } return false; } internal static bool IsTwoHanded(ItemData item) { //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_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Invalid comparison between Unknown and I4 //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Invalid comparison between Unknown and I4 ItemType itemType = item.m_shared.m_itemType; if ((int)itemType != 14) { return (int)itemType == 22; } return true; } internal static bool IsShield(ItemData item) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Invalid comparison between Unknown and I4 return (int)item.m_shared.m_itemType == 5; } internal static bool IsArmor(ItemData item) { //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_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Invalid comparison between Unknown and I4 //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Invalid comparison between Unknown and I4 //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Invalid comparison between Unknown and I4 //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Invalid comparison between Unknown and I4 ItemType itemType = item.m_shared.m_itemType; if ((int)itemType != 6 && (int)itemType != 7 && (int)itemType != 11) { return (int)itemType == 17; } return true; } internal static bool IsTool(ItemData item) { return item.m_customData.ContainsKey("ymiron_tool"); } internal static bool IsOutfit(ItemData item) { return item.m_customData.ContainsKey("ymiron_outfit"); } internal static bool IsReal(ItemData item) { if (!IsTool(item)) { return !IsOutfit(item); } return false; } internal static float Score(ItemData item) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0038: 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_0046: Unknown result type (might be due to invalid IL or missing references) if (IsMeleeWeapon(item)) { DamageTypes damage = item.GetDamage(); return 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; } if (IsShield(item)) { return item.GetBaseBlockPower(); } if (!IsArmor(item)) { return 0f; } return item.GetArmor(); } internal static string Slot(ItemData item) { if (IsMeleeWeapon(item)) { return "weapon"; } if (!IsShield(item)) { return ((object)Unsafe.As<ItemType, ItemType>(ref item.m_shared.m_itemType)/*cast due to .constrained prefix*/).ToString(); } return "shield"; } } public enum JobKind { Woodcutter, Stonecutter, Farmer, Stoker, Caretaker } internal static class ModConfig { internal static ConfigEntry<float> Health; internal static ConfigEntry<string> Outfits; internal static ConfigEntry<float> WanderRadius; internal static ConfigEntry<float> VillageRadius; internal static ConfigEntry<bool> ShowOnMap; internal static ConfigEntry<bool> DeathPins; internal static ConfigEntry<float> WanderInterval; internal static ConfigEntry<string> MarkerRequirements; internal static ConfigEntry<float> MarkerLinkDistance; internal static ConfigEntry<KeyboardShortcut> MarkerToggleKey; internal static ConfigEntry<bool> MarkersVisible; internal static ConfigEntry<bool> UnstuckTeleport; internal static ConfigEntry<bool> VerboseLog; internal static ConfigEntry<float> UnstuckTeleportDelay; internal static ConfigEntry<float> ThreatRadius; internal static ConfigEntry<float> FleeDistance; internal static ConfigEntry<float> BedSearchRadius; internal static ConfigEntry<float> FireSearchRadius; internal static ConfigEntry<string> LodgeRequirements; internal static ConfigEntry<int> LodgeWidth; internal static ConfigEntry<int> LodgeHeight; internal static ConfigEntry<float> JobSearchRadius; internal static ConfigEntry<float> WorkRadius; internal static ConfigEntry<float> TreeSafetyRadius; internal static ConfigEntry<float> SwingInterval; internal static ConfigEntry<float> ChopPower; internal static ConfigEntry<float> OfflineSecondsPerTree; internal static ConfigEntry<float> OfflineMaxDays; internal static ConfigEntry<string> WoodProducts; internal static ConfigEntry<string> StoneProducts; internal static ConfigEntry<int> ToolWearPerItem; internal static ConfigEntry<string> ZoneRequirements; internal static ConfigEntry<float> ZoneRadius; internal static ConfigEntry<float> ZoneLinkRadius; internal static ConfigEntry<string> StorehouseRequirements; internal static ConfigEntry<int> StorehouseWidth; internal static ConfigEntry<int> StorehouseHeight; internal static ConfigEntry<string> QuarryRequirements; internal static ConfigEntry<string> QuarryZoneRequirements; internal static ConfigEntry<float> MinePower; internal static ConfigEntry<float> OfflineSecondsPerRock; internal static ConfigEntry<string> FarmRequirements; internal static ConfigEntry<string> FieldRequirements; internal static ConfigEntry<float> FieldRadius; internal static ConfigEntry<int> SeedReserve; internal static ConfigEntry<int> KeepForSowing; internal static ConfigEntry<int> HarvestCarry; internal static ConfigEntry<string> ShedRequirements; internal static ConfigEntry<float> StokerRadius; internal static ConfigEntry<string> StokerStations; internal static ConfigEntry<int> AptitudeBonus; internal static ConfigEntry<int> RecruitCostPerTalentLevel; internal static ConfigEntry<string> HallRequirements; internal static ConfigEntry<float> HallRadius; internal static ConfigEntry<string> WorkshopRequirements; internal static ConfigEntry<float> CaretakerRadius; internal static ConfigEntry<int> FuelBelow; internal static ConfigEntry<int> RepairBelow; internal static ConfigEntry<int> ToolRepairBelow; internal static ConfigEntry<float> ToolRadius; internal static ConfigEntry<bool> SortIntoDrawers; internal static ConfigEntry<float> DrawerRadius; internal static ConfigEntry<bool> CollectItems; internal static ConfigEntry<float> CollectDelay; i