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 Cozy Critters v0.1.1
CozyCritters.dll
Decompiled 2 hours ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using UnityEngine; using UnityEngine.Audio; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("CozyCritters")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.1.1.0")] [assembly: AssemblyInformationalVersion("0.1.1+fd151acdae3a8feabaadfc8aeee78ad23c5acd27")] [assembly: AssemblyProduct("CozyCritters")] [assembly: AssemblyTitle("CozyCritters")] [assembly: AssemblyVersion("0.1.1.0")] namespace CozyCritters; public class Cage : MonoBehaviour, Hoverable, Interactable { public const int Capacity = 4; public static readonly List<Cage> All = new List<Cage>(); private static readonly int KId = StringExtensionMethods.GetStableHashCode("cc_cageid"); private static readonly int KFood = StringExtensionMethods.GetStableHashCode("cc_bowl"); public const int BowlMax = 20; private const float InX = 0.56f; private const float InZ = 0.29f; private const float Floor = 0.09f; private static readonly Rect House = new Rect(0.2f, -0.31f, 0.4f, 0.34f); private ZNetView m_nview; private Piece m_piece; private GameObject m_bowlFood; private float m_bowlTick; public long Id { get { if (!Object.op_Implicit((Object)(object)m_nview) || !m_nview.IsValid()) { return 0L; } return m_nview.GetZDO().GetLong(KId, 0L); } } public int FoodCount => BowlItems().Length; public ZNetView NView => m_nview; public Vector3 BowlCenter => ((Component)this).transform.TransformPoint(new Vector3(-0.42f, 0.09f, 0.15f)); public Vector3 BowlSpot => ((Component)this).transform.TransformPoint(new Vector3(-0.26f, 0.09f, 0.12f)); public float FloorY => ((Component)this).transform.position.y + 0.09f; public Vector3 DoorOutside => ((Component)this).transform.TransformPoint(new Vector3(0f, 0f, 0.62f)); public Vector3 HouseDoor => ((Component)this).transform.TransformPoint(new Vector3(0.38f, 0.09f, 0.08f)); private void Awake() { m_nview = ((Component)this).GetComponent<ZNetView>(); m_piece = ((Component)this).GetComponent<Piece>(); All.Add(this); Transform[] componentsInChildren = ((Component)this).GetComponentsInChildren<Transform>(true); foreach (Transform val in componentsInChildren) { if (((Object)val).name == "BowlFood") { m_bowlFood = ((Component)val).gameObject; } } if (Object.op_Implicit((Object)(object)m_nview) && m_nview.IsValid()) { if (m_nview.IsOwner() && m_nview.GetZDO().GetLong(KId, 0L) == 0L) { m_nview.GetZDO().Set(KId, ((long)Random.Range(1, int.MaxValue) << 31) ^ Random.Range(1, int.MaxValue)); } m_nview.Register<string, int>("CC_AddFood", (Action<long, string, int>)RPC_AddFood); m_nview.Register<long>("CC_TakeFood", (Action<long, long>)RPC_TakeFood); } } private void Update() { m_bowlTick -= Time.deltaTime; if (!(m_bowlTick > 0f) && Object.op_Implicit((Object)(object)m_bowlFood)) { m_bowlTick = 0.5f; bool flag = FoodCount > 0; if (m_bowlFood.activeSelf != flag) { m_bowlFood.SetActive(flag); } } } private string[] BowlItems() { if (!Object.op_Implicit((Object)(object)m_nview) || !m_nview.IsValid()) { return new string[0]; } string text = m_nview.GetZDO().GetString(KFood, ""); if (!string.IsNullOrEmpty(text)) { return text.Split(','); } return new string[0]; } private void RPC_AddFood(long sender, string food, int n) { if (!m_nview.IsOwner()) { return; } List<string> list = new List<string>(BowlItems()); for (int i = 0; i < n; i++) { if (list.Count >= 20) { break; } list.Add(food); } m_nview.GetZDO().Set(KFood, string.Join(",", list)); } private void RPC_TakeFood(long sender, long critterUid) { if (!m_nview.IsOwner()) { return; } List<string> list = new List<string>(BowlItems()); if (list.Count == 0) { return; } Critter critter = null; foreach (Critter item in Critter.All) { if (Object.op_Implicit((Object)(object)item) && item.Uid == critterUid) { critter = item; break; } } if (!((Object)(object)critter == (Object)null)) { string text = list[0]; list.RemoveAt(0); m_nview.GetZDO().Set(KFood, string.Join(",", list)); critter.NView.InvokeRPC("CC_Feed", new object[1] { text }); } } private void OnDestroy() { All.Remove(this); } public static Cage Find(long id) { if (id == 0L) { return null; } foreach (Cage item in All) { if (Object.op_Implicit((Object)(object)item) && item.Id == id) { return item; } } return null; } public bool Contains(Vector3 world) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0007: 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_000d: 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_0031: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) Vector3 val = ((Component)this).transform.InverseTransformPoint(world); if (Mathf.Abs(val.x) <= 0.61f && Mathf.Abs(val.z) <= 0.34f && val.y > -0.2f) { return val.y < 0.8f; } return false; } public Vector3 ClampInside(Vector3 world) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0007: 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: 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_0045: 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) //IL_0088: 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_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) Vector3 val = ((Component)this).transform.InverseTransformPoint(world); val.x = Mathf.Clamp(val.x, -0.56f, 0.56f); val.z = Mathf.Clamp(val.z, -0.29f, 0.29f); if (InHouse(val)) { Rect house = House; float y = ((Rect)(ref house)).y; house = House; val.z = y + ((Rect)(ref house)).height + 0.01f; } val.y = 0.09f; return ((Component)this).transform.TransformPoint(val); } private static bool InHouse(Vector3 l) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: 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_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //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_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) float x = l.x; Rect house = House; if (x > ((Rect)(ref house)).x) { float x2 = l.x; house = House; float x3 = ((Rect)(ref house)).x; house = House; if (x2 < x3 + ((Rect)(ref house)).width) { float z = l.z; house = House; if (z > ((Rect)(ref house)).y) { float z2 = l.z; house = House; float y = ((Rect)(ref house)).y; house = House; return z2 < y + ((Rect)(ref house)).height; } } } return false; } public Vector3 RandomInside() { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) Vector3 val = default(Vector3); for (int i = 0; i < 12; i++) { ((Vector3)(ref val))..ctor(Random.Range(-0.56f, 0.56f), 0.09f, Random.Range(-0.29f, 0.29f)); if (!InHouse(val)) { return ((Component)this).transform.TransformPoint(val); } } return ((Component)this).transform.TransformPoint(new Vector3(-0.2f, 0.09f, 0.1f)); } public int Count() { long id = Id; int num = 0; foreach (Critter item in Critter.All) { if (Object.op_Implicit((Object)(object)item) && item.CageId == id) { num++; } } return num; } public float GetHoverOffset() { return 0f; } public string GetHoverName() { return Localization.instance.Localize("$cc_cage"); } public string GetHoverText() { if (!Object.op_Implicit((Object)(object)m_nview) || !m_nview.IsValid()) { return ""; } int num = Count(); string text = "$cc_cage (" + num + "/" + 4 + ")"; ItemData val = Held.HeldItem(Player.m_localPlayer); text = ((val == null) ? (text + "\n[<color=yellow><b>$KEY_Use</b></color>] $cc_call_home") : (text + "\n[<color=yellow><b>$KEY_Use</b></color>] " + Localization.instance.Localize("$cc_put_in", new string[1] { Held.DisplayName(val) }))); if (num > 0) { text += "\n[<color=yellow><b>$KEY_AltPlace + $KEY_Use</b></color>] $cc_let_out"; } text = text + "\n$cc_bowl " + FoodCount + "/" + 20 + " [<color=yellow><b>1-8</b></color>] $cc_fill_bowl"; return Localization.instance.Localize(text); } public bool Interact(Humanoid user, bool hold, bool alt) { if (!hold) { Player val = (Player)(object)((user is Player) ? user : null); if (val != null && Object.op_Implicit((Object)(object)m_nview) && m_nview.IsValid()) { if (alt) { long id = Id; int num = 0; Critter[] array = Critter.All.ToArray(); foreach (Critter critter in array) { if (Object.op_Implicit((Object)(object)critter) && critter.CageId == id) { critter.NView.InvokeRPC("CC_Release", Array.Empty<object>()); num++; } } if (num > 0) { ((Character)val).Message((MessageType)2, "$cc_let_out_done", 0, (Sprite)null, false); } return true; } ItemData val2 = Held.HeldItem(val); if (val2 != null) { return PutIn(val, val2); } CallHome(val); return true; } } return false; } public bool UseItem(Humanoid user, ItemData item) { //IL_00d7: Unknown result type (might be due to invalid IL or missing references) Player val = (Player)(object)((user is Player) ? user : null); if (val == null || item == null || !Object.op_Implicit((Object)(object)m_nview) || !m_nview.IsValid()) { return false; } if (Held.IsCritterItem(item)) { return PutIn(val, item); } string text = (Object.op_Implicit((Object)(object)item.m_dropPrefab) ? ((Object)item.m_dropPrefab).name : ""); if (!Food.Accepts(text)) { return false; } int num = 20 - FoodCount; if (num <= 0) { ((Character)val).Message((MessageType)2, "$cc_bowl_full", 0, (Sprite)null, false); return true; } int num2 = Mathf.Min(new int[3] { 5, num, item.m_stack }); ((Humanoid)val).GetInventory().RemoveItem(item, num2); m_nview.InvokeRPC("CC_AddFood", new object[2] { text, num2 }); Prefabs.PlayAt("eat_crunch", BowlSpot, 0.5f); ((Character)val).Message((MessageType)1, Localization.instance.Localize("$cc_bowl_added", new string[1] { num2.ToString() }), 0, (Sprite)null, false); return true; } private bool PutIn(Player p, ItemData item) { //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_005c: 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_0089: 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) if (Count() >= 4) { ((Character)p).Message((MessageType)2, "$cc_cage_full", 0, (Sprite)null, false); return true; } CritterData d = Held.ReadItem(item); if (item.m_equipped) { ((Humanoid)p).UnequipItem(item, true); } ((Humanoid)p).GetInventory().RemoveItem(item); Critter.Spawn(d, RandomInside(), Quaternion.Euler(0f, Random.Range(0f, 360f), 0f), Id, 0L); Prefabs.PlayAt("box_pop", ((Component)this).transform.position + Vector3.up * 0.2f, 0.6f); return true; } private void CallHome(Player p) { //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) int num = 4 - Count(); if (num <= 0) { ((Character)p).Message((MessageType)2, "$cc_cage_full", 0, (Sprite)null, false); return; } List<Critter> list = new List<Critter>(); foreach (Critter item in Critter.All) { if (Object.op_Implicit((Object)(object)item) && Object.op_Implicit((Object)(object)item.NView) && item.NView.IsValid() && item.CageId == 0L && Vector3.Distance(((Component)item).transform.position, ((Component)this).transform.position) < 20f) { list.Add(item); } } list.Sort((Critter a, Critter b) => Vector3.Distance(((Component)a).transform.position, ((Component)this).transform.position).CompareTo(Vector3.Distance(((Component)b).transform.position, ((Component)this).transform.position))); int num2 = 0; foreach (Critter item2 in list) { if (num2 >= num) { break; } item2.NView.InvokeRPC("CC_GoHome", new object[1] { Id }); num2++; } ((Character)p).Message((MessageType)2, (num2 > 0) ? "$cc_called" : "$cc_nobody_to_call", 0, (Sprite)null, false); } } public enum Species { Hamster, GuineaPig } public enum Rarity { Common, Uncommon, Rare, Legendary } public class Coat { public string Key; public Color Fur; public Color Belly; public Color Patch; public Rarity Rarity; public bool Shiny; public float Weight => Rarity switch { Rarity.Common => 10f, Rarity.Uncommon => 4f, Rarity.Rare => 1.3f, _ => 0.45f, }; public Coat(string key, string fur, string belly, string patch, Rarity r, bool shiny = false) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) Key = key; Fur = Hex(fur); Belly = Hex(belly); Patch = ((patch == null) ? Fur : Hex(patch)); Rarity = r; Shiny = shiny; } private static Color Hex(string h) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) Color result = default(Color); ColorUtility.TryParseHtmlString("#" + h, ref result); return result; } } public static class Coats { public static readonly Coat[] Hamster = new Coat[11] { new Coat("golden", "D9963F", "F5EBDD", null, Rarity.Common), new Coat("black", "2B2725", "45403C", null, Rarity.Common), new Coat("grey", "8D8A86", "D8D3CC", null, Rarity.Common), new Coat("greywhite", "9A9895", "F4F1EC", "F4F1EC", Rarity.Common), new Coat("cream", "EAD3A8", "FAF3E6", null, Rarity.Common), new Coat("cinnamon", "B36A3C", "EFD9C3", null, Rarity.Uncommon), new Coat("panda", "2A2626", "F2EFEA", "F2EFEA", Rarity.Uncommon), new Coat("sable", "5A4433", "8A7461", null, Rarity.Uncommon), new Coat("snow", "F7F5F2", "FFFFFF", null, Rarity.Rare), new Coat("lilac", "A99AAE", "E8E1EA", null, Rarity.Rare), new Coat("odingold", "F2C14E", "FFE9A8", "FFD36B", Rarity.Legendary, shiny: true) }; public static readonly Coat[] GuineaPig = new Coat[11] { new Coat("ginger", "C77B3A", "F2E3CF", null, Rarity.Common), new Coat("white", "F4F2EE", "FFFFFF", null, Rarity.Common), new Coat("black", "2D2926", "45403C", null, Rarity.Common), new Coat("gingerwhite", "F1ECE3", "F7F2EA", "C77B3A", Rarity.Common), new Coat("dutch", "F1ECE3", "F7F2EA", "2D2926", Rarity.Uncommon), new Coat("agouti", "8A6E4E", "C8B193", null, Rarity.Common), new Coat("cream", "E9D3A6", "F7EBD3", null, Rarity.Common), new Coat("chocolate", "5B3A29", "7A5440", null, Rarity.Uncommon), new Coat("lilac", "B5A4B8", "E5DCE7", null, Rarity.Rare), new Coat("moon", "C9CED6", "EEF1F5", "6E7685", Rarity.Rare), new Coat("odingold", "F2C14E", "FFE9A8", "FFD36B", Rarity.Legendary, shiny: true) }; public static Coat[] For(Species s) { if (s != Species.GuineaPig) { return Hamster; } return GuineaPig; } public static Coat Get(Species s, int i) { Coat[] array = For(s); return array[Mathf.Clamp(i, 0, array.Length - 1)]; } public static int Roll(Species s, Random rng) { Coat[] array = For(s); float num = 0f; Coat[] array2 = array; foreach (Coat coat in array2) { num += coat.Weight; } float num2 = (float)rng.NextDouble() * num; for (int j = 0; j < array.Length; j++) { num2 -= array[j].Weight; if (num2 <= 0f) { return j; } } return 0; } public static int Mix(Species s, int a, int b, Random rng) { double num = rng.NextDouble(); if (num < 0.4) { return a; } if (num < 0.8) { return b; } if (num < 0.95) { return Blend(s, a, b); } return Roll(s, rng); } public static int Blend(Species s, int a, int b) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002c: 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_0033: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) Coat[] array = For(s); Coat coat = Get(s, a); Coat coat2 = Get(s, b); Color y = Color.Lerp(coat.Fur, coat2.Fur, 0.5f); Color y2 = Color.Lerp(coat.Belly, coat2.Belly, 0.5f); int result = a; float num = float.MaxValue; for (int i = 0; i < array.Length; i++) { if (array[i].Rarity != Rarity.Legendary || i == a || i == b) { float num2 = Dist(array[i].Fur, y) * 2f + Dist(array[i].Belly, y2); if (i == a || i == b) { num2 += 0.02f; } if (num2 < num) { num = num2; result = i; } } } return result; } private static float Dist(Color x, Color y) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_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_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0044: 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) return (x.r - y.r) * (x.r - y.r) + (x.g - y.g) * (x.g - y.g) + (x.b - y.b) * (x.b - y.b); } } public static class Food { private static readonly HashSet<string> HamsterFav = new HashSet<string> { "BeechSeeds", "Acorn", "BirchSeeds", "CarrotSeeds", "TurnipSeeds", "OnionSeeds", "Barley", "Flax" }; private static readonly HashSet<string> GuineaFav = new HashSet<string> { "Carrot", "Dandelion", "Thistle", "Fiddleheadfern", "Turnip" }; private static readonly HashSet<string> All = new HashSet<string> { "Raspberry", "Blueberries", "Cloudberry", "Vineberry", "Carrot", "Turnip", "Dandelion", "Thistle", "Fiddleheadfern", "Barley", "Flax", "BeechSeeds", "Acorn", "BirchSeeds", "CarrotSeeds", "TurnipSeeds", "OnionSeeds" }; public static bool Accepts(string prefab) { return All.Contains(prefab); } public static bool IsFavourite(Species s, string prefab) { return ((s == Species.GuineaPig) ? GuineaFav : HamsterFav).Contains(prefab); } } public class Critter : MonoBehaviour, Hoverable, Interactable, TextReceiver { private enum Act { Idle, Walk, Eat, Happy, Sleep, GoEat } public enum Fx { Pet = 1, Eat, EatFav, Born } public Species Species; public static readonly List<Critter> All = new List<Critter>(); public static readonly int KCage = StringExtensionMethods.GetStableHashCode("cc_cage"); public static readonly int KHome = StringExtensionMethods.GetStableHashCode("cc_home"); public static readonly int KUid = StringExtensionMethods.GetStableHashCode("cc_uid"); public static readonly int KNamer = StringExtensionMethods.GetStableHashCode("cc_namer"); public static readonly int KAwake = StringExtensionMethods.GetStableHashCode("cc_awake"); public static readonly int KGoHome = StringExtensionMethods.GetStableHashCode("cc_gohome"); public static readonly int KPetT = StringExtensionMethods.GetStableHashCode("cc_petT"); private ZNetView m_nview; private CritterAnim m_anim; private AudioSource m_audio; private Act m_act; private float m_timer; private Vector3 m_target; private float m_stuck; private float m_tick; private float m_needsTick; private float m_breedTick; private float m_lookTick; private float m_pressTime = -10f; private bool m_pickedUp; private int m_appliedCoat = -1; private Vector3 m_lastPos; private float m_nextSqueak; private float m_nextEmote; private float m_cageMissing; private float m_nextBowl; private bool m_namePrompted; private bool m_bornFxDone; public ZNetView NView => m_nview; public long Uid { get { if (!Object.op_Implicit((Object)(object)m_nview) || !m_nview.IsValid()) { return 0L; } return m_nview.GetZDO().GetLong(KUid, 0L); } } public long CageId { get { if (!Object.op_Implicit((Object)(object)m_nview) || !m_nview.IsValid()) { return 0L; } return m_nview.GetZDO().GetLong(KCage, 0L); } } public CritterData Data => CritterData.FromZDO(m_nview.GetZDO()); private float Speed => ((Species == Species.GuineaPig) ? 0.38f : 0.5f) * ((((Component)this).transform.localScale.x < 0.9f) ? 0.8f : 1f); private string SpeciesName { get { if (Species != Species.GuineaPig) { return "$cc_hamster"; } return "$cc_guineapig"; } } private void Awake() { //IL_0036: 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) m_nview = ((Component)this).GetComponent<ZNetView>(); m_anim = ((Component)this).GetComponentInChildren<CritterAnim>(); m_audio = ((Component)this).GetComponent<AudioSource>(); All.Add(this); m_lastPos = ((Component)this).transform.position; m_nextSqueak = Time.time + Random.Range(4f, 15f); m_nextEmote = Time.time + Random.Range(5f, 12f); if (!((Object)(object)m_nview == (Object)null) && m_nview.GetZDO() != null) { m_nview.Register("CC_Pet", (Action<long>)RPC_Pet); m_nview.Register<string>("CC_Feed", (Action<long, string>)RPC_Feed); m_nview.Register<string>("CC_Name", (Action<long, string>)RPC_Name); m_nview.Register<int>("CC_Fx", (Action<long, int>)RPC_Fx); m_nview.Register("CC_Bred", (Action<long>)RPC_Bred); m_nview.Register<long>("CC_Enter", (Action<long, long>)RPC_Enter); m_nview.Register("CC_Release", (Action<long>)RPC_Release); m_nview.Register<long>("CC_GoHome", (Action<long, long>)RPC_GoHome); m_nview.Register<string>("CC_BabyMsg", (Action<long, string>)RPC_BabyMsg); if (m_nview.IsOwner() && m_nview.GetZDO().GetLong(KUid, 0L) == 0L) { m_nview.GetZDO().Set(KUid, ((long)Random.Range(1, int.MaxValue) << 31) ^ Random.Range(1, int.MaxValue)); } } } private void OnDestroy() { All.Remove(this); } public static Critter Spawn(CritterData d, Vector3 pos, Quaternion rot, long cageId, long namer) { //IL_0015: 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_005b: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) Critter component = Object.Instantiate<GameObject>(ZNetScene.instance.GetPrefab(Prefabs.CritterPrefabName(d.Species)), pos, rot).GetComponent<Critter>(); ZDO zDO = component.m_nview.GetZDO(); long now = CritterData.Now; if (d.HappyT == 0L) { d.HappyT = now; } d.ToZDO(zDO); zDO.Set(KCage, cageId); zDO.Set(KHome, pos); zDO.Set(KNamer, namer); component.m_lastPos = pos; return component; } private void Update() { //IL_0151: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_017f: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Unknown result type (might be due to invalid IL or missing references) //IL_01a5: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)m_nview == (Object)null || !m_nview.IsValid()) { return; } ZDO zDO = m_nview.GetZDO(); long now = CritterData.Now; float deltaTime = Time.deltaTime; m_tick -= deltaTime; if (m_tick <= 0f) { m_tick = 0.5f; int num = zDO.GetInt(CritterData.KCoat, 0); if (num != m_appliedCoat) { m_appliedCoat = num; Looks.ApplyCoat(((Component)m_anim).gameObject, Species, num); } CritterData critterData = CritterData.FromZDO(zDO); ((Component)this).transform.localScale = Vector3.one * critterData.Scale(now); if (Object.op_Implicit((Object)(object)m_anim)) { m_anim.Sad = critterData.Happy < 30f; } if (!m_bornFxDone) { m_bornFxDone = true; if ((now - critterData.Born >= 0 && now - critterData.Born < 4) || (zDO.GetLong(KNamer, 0L) != 0L && now - critterData.Fed < 4)) { PlayFx(Fx.Born); } } AskNameIfMine(zDO); } bool flag = IsSleepingTime(zDO, now); if (Object.op_Implicit((Object)(object)m_anim)) { Vector3 position = ((Component)this).transform.position; float num2; if (!(deltaTime > 0f)) { num2 = 0f; } else { Vector3 val = new Vector3(position.x - m_lastPos.x, 0f, position.z - m_lastPos.z); num2 = ((Vector3)(ref val)).magnitude / deltaTime; } float num3 = num2; m_lastPos = position; m_anim.Speed = num3; m_anim.Sleeping = flag && num3 < 0.05f; } LocalAmbience(flag, zDO); if (m_nview.IsOwner()) { OwnerNeeds(zDO, now, deltaTime); OwnerAI(zDO, now, deltaTime, flag); } } private static bool IsSleepingTime(ZDO zdo, long now) { if (EnvMan.IsNight()) { return now > zdo.GetLong(KAwake, 0L); } return false; } private void LocalAmbience(bool sleeping, ZDO zdo) { float time = Time.time; if (time > m_nextSqueak) { if (sleeping) { m_nextSqueak = time + Random.Range(7f, 14f); Emote.Show(Emote.Kind.Zzz, ((Component)this).transform, HeadHeight()); } else { m_nextSqueak = time + Random.Range(10f, 30f); if (Random.value < 0.55f) { PlayVoice(happy: false); } } } if (!sleeping && time > m_nextEmote) { m_nextEmote = time + Random.Range(14f, 26f); if (zdo.GetFloat(CritterData.KHappy, 70f) < 30f) { Emote.Show(Emote.Kind.Cloud, ((Component)this).transform, HeadHeight()); } else if (Coats.Get(Species, zdo.GetInt(CritterData.KCoat, 0)).Shiny) { Emote.Show(Emote.Kind.Star, ((Component)this).transform, HeadHeight()); } } } private float HeadHeight() { //IL_001b: Unknown result type (might be due to invalid IL or missing references) return ((Species == Species.GuineaPig) ? 0.32f : 0.27f) * ((Component)this).transform.localScale.y; } private void OwnerNeeds(ZDO zdo, long now, float dt) { //IL_00bf: Unknown result type (might be due to invalid IL or missing references) m_needsTick -= dt; if (m_needsTick > 0f) { return; } m_needsTick = 10f; CritterData critterData = CritterData.FromZDO(zdo); long num = zdo.GetLong(KCage, 0L); bool hasFriends = num != 0L && CountInCage(num) > 1; critterData.TickHappiness(now, hasFriends); zdo.Set(CritterData.KHappy, critterData.Happy); zdo.Set(CritterData.KHappyT, critterData.HappyT); if (num != 0L) { if ((Object)(object)Cage.Find(num) == (Object)null) { m_cageMissing += 10f; if (m_cageMissing >= 20f) { zdo.Set(KCage, 0L); zdo.Set(KHome, ((Component)this).transform.position); } } else { m_cageMissing = 0f; } } m_breedTick -= 10f; if (m_breedTick <= 0f) { m_breedTick = 30f; TryBreed(zdo, critterData, now); } } private static int CountInCage(long cageId) { int num = 0; foreach (Critter item in All) { if (Object.op_Implicit((Object)(object)item) && Object.op_Implicit((Object)(object)item.m_nview) && item.m_nview.IsValid() && item.CageId == cageId) { num++; } } return num; } private bool CanBreed(CritterData d, long now) { if (d.IsAdult(now) && d.Fullness(now) > 0.15f && d.Happy >= 60f) { return (float)(now - d.Bred) >= CritterData.DayLen * 2f; } return false; } private void TryBreed(ZDO zdo, CritterData d, long now) { //IL_0179: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Unknown result type (might be due to invalid IL or missing references) if (!Plugin.Breeding.Value) { return; } long num = zdo.GetLong(KCage, 0L); if (num == 0L || !CanBreed(d, now)) { return; } Cage cage = Cage.Find(num); if ((Object)(object)cage == (Object)null || CountInCage(num) >= 4) { return; } long num2 = zdo.GetLong(KUid, 0L); Critter critter = null; foreach (Critter item in All) { if (!((Object)(object)item == (Object)(object)this) && Object.op_Implicit((Object)(object)item) && Object.op_Implicit((Object)(object)item.m_nview) && item.m_nview.IsValid() && item.Species == Species && item.CageId == num && CanBreed(item.Data, now)) { critter = item; break; } } if (!((Object)(object)critter == (Object)null) && critter.Uid >= num2) { float num3 = 30f / (CritterData.DayLen * 0.75f); if (!(Random.value > num3)) { CritterData data = critter.Data; Random rng = new Random(Random.Range(int.MinValue, int.MaxValue)); Spawn(new CritterData { Species = Species, Coat = Coats.Mix(Species, d.Coat, data.Coat, rng), Born = now, Fed = now, Happy = 75f }, cage.RandomInside(), Quaternion.Euler(0f, Random.Range(0f, 360f), 0f), num, 0L); zdo.Set(CritterData.KBred, now); critter.m_nview.InvokeRPC("CC_Bred", Array.Empty<object>()); string text = (string.IsNullOrEmpty(d.Name) ? ("$cc_" + Species.ToString().ToLowerInvariant()) : d.Name); string text2 = (string.IsNullOrEmpty(data.Name) ? ("$cc_" + Species.ToString().ToLowerInvariant()) : data.Name); m_nview.InvokeRPC(ZNetView.Everybody, "CC_BabyMsg", new object[1] { text + "\n" + text2 }); } } } private void RPC_BabyMsg(long sender, string names) { //IL_0014: 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) Player localPlayer = Player.m_localPlayer; if (Object.op_Implicit((Object)(object)localPlayer) && !(Vector3.Distance(((Component)localPlayer).transform.position, ((Component)this).transform.position) > 40f)) { string[] array = names.Split('\n'); string text = Localization.instance.Localize("$cc_baby_born", new string[2] { Localization.instance.Localize(array[0]), (array.Length > 1) ? Localization.instance.Localize(array[1]) : "" }); MessageHud.instance.ShowMessage((MessageType)2, text, 0, (Sprite)null, false, true); } } private void RPC_Bred(long sender) { if (m_nview.IsOwner()) { m_nview.GetZDO().Set(CritterData.KBred, CritterData.Now); } } private void OwnerAI(ZDO zdo, long now, float dt, bool sleepingTime) { //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) //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_0399: Unknown result type (might be due to invalid IL or missing references) //IL_039f: Unknown result type (might be due to invalid IL or missing references) //IL_03a4: Unknown result type (might be due to invalid IL or missing references) //IL_02b2: Unknown result type (might be due to invalid IL or missing references) //IL_02b8: Unknown result type (might be due to invalid IL or missing references) //IL_02bd: Unknown result type (might be due to invalid IL or missing references) //IL_0303: Unknown result type (might be due to invalid IL or missing references) //IL_030e: Unknown result type (might be due to invalid IL or missing references) //IL_0313: Unknown result type (might be due to invalid IL or missing references) //IL_0318: Unknown result type (might be due to invalid IL or missing references) //IL_031d: Unknown result type (might be due to invalid IL or missing references) //IL_0321: Unknown result type (might be due to invalid IL or missing references) //IL_0326: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0113: 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_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_01fd: Unknown result type (might be due to invalid IL or missing references) //IL_0202: Unknown result type (might be due to invalid IL or missing references) //IL_0207: Unknown result type (might be due to invalid IL or missing references) //IL_0211: Unknown result type (might be due to invalid IL or missing references) //IL_0216: Unknown result type (might be due to invalid IL or missing references) //IL_021b: Unknown result type (might be due to invalid IL or missing references) long num = zdo.GetLong(KCage, 0L); Cage cage = ((num != 0L) ? Cage.Find(num) : null); long num2 = zdo.GetLong(KGoHome, 0L); if (num2 != 0L) { Cage cage2 = Cage.Find(num2); if (!((Object)(object)cage2 == (Object)null) && cage2.Count() < 4) { m_target = cage2.DoorOutside; if (Flat(((Component)this).transform.position - m_target) < 0.25f || m_stuck > 6f) { EnterCage(cage2); } else if (!Step(cage, dt)) { m_stuck += dt; } return; } zdo.Set(KGoHome, 0L); } if (sleepingTime && m_act != Act.Eat && m_act != Act.Happy) { if ((Object)(object)cage != (Object)null && Flat(((Component)this).transform.position - cage.HouseDoor) > 0.22f && m_stuck < 4f) { m_target = cage.HouseDoor + Random.insideUnitSphere.Flat() * 0.08f; if (!Step(cage, dt)) { m_stuck += dt; } } m_act = Act.Sleep; return; } if (m_act == Act.Sleep) { m_act = Act.Idle; m_timer = Random.Range(1f, 3f); m_stuck = 0f; } switch (m_act) { case Act.Idle: m_timer -= dt; if (m_timer <= 0f) { if ((Object)(object)cage != (Object)null && Time.time > m_nextBowl && cage.FoodCount > 0 && CritterData.FromZDO(zdo).Fullness(now) < 0.35f) { m_act = Act.GoEat; m_target = cage.BowlSpot + Random.insideUnitSphere.Flat() * 0.07f; m_stuck = 0f; m_timer = 10f; } else if (ChooseTarget(cage, zdo)) { m_act = Act.Walk; m_stuck = 0f; m_timer = 8f; } else { m_timer = Random.Range(1f, 3f); } } break; case Act.GoEat: m_timer -= dt; if (!Step(cage, dt)) { m_stuck += dt; } if ((Object)(object)cage == (Object)null) { m_act = Act.Idle; } else if (Flat(((Component)this).transform.position - m_target) < 0.06f || m_timer <= 0f || m_stuck > 2f) { m_nextBowl = Time.time + 20f; Transform transform = ((Component)this).transform; Vector3 val = (cage.BowlCenter - ((Component)this).transform.position).Flat(); transform.rotation = Quaternion.LookRotation(((Vector3)(ref val)).normalized); cage.NView.InvokeRPC("CC_TakeFood", new object[1] { zdo.GetLong(KUid, 0L) }); m_act = Act.Idle; m_timer = 1f; } break; case Act.Walk: m_timer -= dt; if (!Step(cage, dt) || m_timer <= 0f || Flat(((Component)this).transform.position - m_target) < 0.05f) { m_act = Act.Idle; m_timer = Random.Range(1.5f, 6f); } break; case Act.Eat: case Act.Happy: m_timer -= dt; if (m_timer <= 0f) { m_act = Act.Idle; m_timer = Random.Range(1f, 3f); } break; case Act.Sleep: break; } } private static float Flat(Vector3 v) { //IL_0000: 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_0011: 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) Vector3 val = new Vector3(v.x, 0f, v.z); return ((Vector3)(ref val)).magnitude; } private bool ChooseTarget(Cage cage, ZDO zdo) { //IL_0023: 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_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0040: 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_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_006f: 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_0079: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: 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) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)cage != (Object)null) { m_target = cage.RandomInside(); return true; } Vector3 vec = zdo.GetVec3(KHome, ((Component)this).transform.position); float value = Plugin.RoamRadius.Value; for (int i = 0; i < 6; i++) { Vector3 val = Random.insideUnitSphere.Flat(); Vector3 normalized = ((Vector3)(ref val)).normalized; Vector3 val2 = ((Component)this).transform.position + normalized * Random.Range(0.4f, 1.8f); if (Flat(val2 - vec) > value) { Vector3 position = ((Component)this).transform.position; val = (vec - ((Component)this).transform.position).Flat(); val2 = position + ((Vector3)(ref val)).normalized * Random.Range(0.4f, 1.2f); } Vector3 val3 = ((Component)this).transform.position + Vector3.up * 0.08f; val = (val2 - ((Component)this).transform.position).Flat(); if (!Physics.Raycast(val3, ((Vector3)(ref val)).normalized, Flat(val2 - ((Component)this).transform.position), Prefabs.SolidMask)) { m_target = val2; return true; } } return false; } private bool Step(Cage cage, float dt) { //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_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: 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_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: 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_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_008d: 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_0097: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: 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_00bc: 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_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: 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_0166: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Unknown result type (might be due to invalid IL or missing references) //IL_017e: Unknown result type (might be due to invalid IL or missing references) //IL_017f: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Unknown result type (might be due to invalid IL or missing references) //IL_0151: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) Vector3 position = ((Component)this).transform.position; Vector3 val = (m_target - position).Flat(); float magnitude = ((Vector3)(ref val)).magnitude; if (magnitude < 0.02f) { return true; } Vector3 val2 = val / magnitude; Vector3 val3 = position + val2 * Mathf.Min(Speed * dt, magnitude); if ((Object)(object)cage != (Object)null && cage.Contains(position)) { val3 = cage.ClampInside(val3); val3.y = cage.FloorY; } else { if (Physics.Raycast(position + Vector3.up * 0.08f, val2, 0.16f, Prefabs.SolidMask)) { return false; } RaycastHit val4 = default(RaycastHit); if (!Physics.Raycast(val3 + Vector3.up * 0.35f, Vector3.down, ref val4, 0.9f, Prefabs.GroundMask)) { return false; } float num = ((RaycastHit)(ref val4)).point.y - position.y; if (num > 0.26f || num < -0.4f) { return false; } if (Object.op_Implicit((Object)(object)ZoneSystem.instance) && ((RaycastHit)(ref val4)).point.y < ZoneSystem.instance.m_waterLevel - 0.05f && ((Component)((RaycastHit)(ref val4)).collider).gameObject.layer == LayerMask.NameToLayer("terrain")) { return false; } val3.y = ((RaycastHit)(ref val4)).point.y; } ((Component)this).transform.position = val3; ((Component)this).transform.rotation = Quaternion.RotateTowards(((Component)this).transform.rotation, Quaternion.LookRotation(val2), 400f * dt); return true; } private void EnterCage(Cage cage) { //IL_002f: 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_0045: Unknown result type (might be due to invalid IL or missing references) ZDO zDO = m_nview.GetZDO(); zDO.Set(KGoHome, 0L); zDO.Set(KCage, cage.Id); ((Component)this).transform.position = cage.RandomInside(); m_lastPos = ((Component)this).transform.position; m_stuck = 0f; m_act = Act.Happy; m_timer = 1f; m_nview.InvokeRPC(ZNetView.Everybody, "CC_Fx", new object[1] { 1 }); } private void RPC_Enter(long sender, long cageId) { if (m_nview.IsOwner()) { Cage cage = Cage.Find(cageId); if ((Object)(object)cage != (Object)null) { EnterCage(cage); } } } private void RPC_GoHome(long sender, long cageId) { if (m_nview.IsOwner()) { m_nview.GetZDO().Set(KGoHome, cageId); m_nview.GetZDO().Set(KAwake, CritterData.Now + 120); m_stuck = 0f; } } private void RPC_Release(long sender) { //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: 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) if (!m_nview.IsOwner()) { return; } ZDO zDO = m_nview.GetZDO(); Cage cage = Cage.Find(zDO.GetLong(KCage, 0L)); zDO.Set(KCage, 0L); if (!((Object)(object)cage == (Object)null)) { Vector3 val = cage.DoorOutside + Random.insideUnitSphere.Flat() * 0.3f; RaycastHit val2 = default(RaycastHit); if (Physics.Raycast(val + Vector3.up * 0.5f, Vector3.down, ref val2, 1.5f, Prefabs.GroundMask)) { val.y = ((RaycastHit)(ref val2)).point.y; } ((Component)this).transform.position = val; m_lastPos = val; zDO.Set(KHome, val); m_act = Act.Idle; m_timer = 0.5f; } } public float GetHoverOffset() { return 0f; } public string GetHoverName() { if (!Object.op_Implicit((Object)(object)m_nview) || !m_nview.IsValid()) { return ""; } string text = m_nview.GetZDO().GetString(CritterData.KName, ""); if (!string.IsNullOrEmpty(text)) { return text; } return Localization.instance.Localize(SpeciesName); } public string GetHoverText() { if (!Object.op_Implicit((Object)(object)m_nview) || !m_nview.IsValid()) { return ""; } ZDO zDO = m_nview.GetZDO(); CritterData critterData = CritterData.FromZDO(zDO); long now = CritterData.Now; Coat coat = Coats.Get(Species, critterData.Coat); StringBuilder stringBuilder = new StringBuilder(); if (!string.IsNullOrEmpty(critterData.Name)) { stringBuilder.Append("<color=#FFD38A>").Append(critterData.Name).Append("</color>\n"); } stringBuilder.Append(SpeciesName).Append(" · $cc_coat_").Append(coat.Key); if (coat.Rarity >= Rarity.Rare) { stringBuilder.Append((coat.Rarity == Rarity.Legendary) ? " <color=#FFD54A>★★</color>" : " <color=#C9A8FF>★</color>"); } if (!critterData.IsAdult(now)) { stringBuilder.Append(" · $cc_baby"); } stringBuilder.Append('\n').Append(Bars(critterData.Fullness(now), critterData.Happy)); if (IsSleepingTime(zDO, now)) { stringBuilder.Append("\n<color=#9FB7FF>$cc_sleeping</color>"); } else if (critterData.Fullness(now) <= 0f) { stringBuilder.Append("\n<color=#FF9A9A>$cc_hungry</color>"); } stringBuilder.Append("\n[<color=yellow><b>$KEY_Use</b></color>] $cc_pet"); stringBuilder.Append("\n[<color=yellow><b>$cc_hold $KEY_Use</b></color>] $cc_pickup"); stringBuilder.Append("\n[<color=yellow><b>$KEY_AltPlace + $KEY_Use</b></color>] $hud_rename"); stringBuilder.Append("\n[<color=yellow><b>1-8</b></color>] $cc_feed"); return Localization.instance.Localize(stringBuilder.ToString()); } public static string Bars(float fullness, float happy) { int num = Mathf.CeilToInt(fullness * 5f - 0.01f); int num2 = Mathf.CeilToInt(happy / 20f - 0.01f); StringBuilder stringBuilder = new StringBuilder("$cc_food "); stringBuilder.Append("<color=#E9B872>").Append('●', Mathf.Clamp(num, 0, 5)).Append("</color><color=#5A5048>") .Append('●', 5 - Mathf.Clamp(num, 0, 5)) .Append("</color>"); stringBuilder.Append(" $cc_mood "); stringBuilder.Append("<color=#FF6F91>").Append('♥', Mathf.Clamp(num2, 0, 5)).Append("</color><color=#5A5048>") .Append('♥', 5 - Mathf.Clamp(num2, 0, 5)) .Append("</color>"); return stringBuilder.ToString(); } public bool Interact(Humanoid user, bool hold, bool alt) { if (Object.op_Implicit((Object)(object)m_nview) && m_nview.IsValid()) { Player val = (Player)(object)((user is Player) ? user : null); if (val != null) { if (alt && !hold) { TextInput.instance.RequestText((TextReceiver)(object)this, "$hud_rename", 16); return true; } if (!hold) { m_pressTime = Time.time; m_nview.InvokeRPC("CC_Pet", Array.Empty<object>()); return true; } if (!m_pickedUp && Time.time - m_pressTime > 0.55f && Time.time - m_pressTime < 3f) { PickUp(val); return true; } return false; } } return false; } public bool UseItem(Humanoid user, ItemData item) { if (!Object.op_Implicit((Object)(object)m_nview) || !m_nview.IsValid() || item == null) { return false; } string text = (Object.op_Implicit((Object)(object)item.m_dropPrefab) ? ((Object)item.m_dropPrefab).name : ""); if (!Food.Accepts(text)) { return false; } if (Data.Fullness(CritterData.Now) > 0.8f) { ((Character)user).Message((MessageType)2, Localization.instance.Localize("$cc_not_hungry", new string[1] { GetHoverName() }), 0, (Sprite)null, false); return true; } user.GetInventory().RemoveOneItem(item); m_nview.InvokeRPC("CC_Feed", new object[1] { text }); return true; } private void PickUp(Player p) { CritterData data = Data; if (Held.GiveItem(p, data) == null) { ((Character)p).Message((MessageType)2, "$inventory_full", 0, (Sprite)null, false); return; } m_pickedUp = true; ((Character)p).Message((MessageType)2, Localization.instance.Localize("$cc_picked_up", new string[1] { GetHoverName() }), 0, (Sprite)null, false); m_nview.ClaimOwnership(); ZNetScene.instance.Destroy(((Component)this).gameObject); } public string GetText() { if (!Object.op_Implicit((Object)(object)m_nview) || !m_nview.IsValid()) { return ""; } return m_nview.GetZDO().GetString(CritterData.KName, ""); } public void SetText(string text) { m_nview.InvokeRPC("CC_Name", new object[1] { text ?? "" }); } private void AskNameIfMine(ZDO zdo) { if (!m_namePrompted) { long num = zdo.GetLong(KNamer, 0L); Player localPlayer = Player.m_localPlayer; if (num != 0L && Object.op_Implicit((Object)(object)localPlayer) && localPlayer.GetPlayerID() == num && !TextInput.IsVisible()) { m_namePrompted = true; TextInput.instance.RequestText((TextReceiver)(object)this, "$cc_name_it", 16); m_nview.InvokeRPC("CC_Name", new object[1] { "\u0001" }); } } } private void RPC_Name(long sender, string text) { if (!m_nview.IsOwner()) { return; } m_nview.GetZDO().Set(KNamer, 0L); if (!(text == "\u0001")) { text = text.Trim(); if (text.Length > 16) { text = text.Substring(0, 16); } m_nview.GetZDO().Set(CritterData.KName, text); m_nview.InvokeRPC(ZNetView.Everybody, "CC_Fx", new object[1] { 1 }); } } private void RPC_Pet(long sender) { if (m_nview.IsOwner()) { ZDO zDO = m_nview.GetZDO(); long now = CritterData.Now; if (IsSleepingTime(zDO, now)) { zDO.Set(KAwake, now + 40); } if (now - zDO.GetLong(KPetT, 0L) >= 20) { zDO.Set(KPetT, now); zDO.Set(CritterData.KHappy, Mathf.Clamp(zDO.GetFloat(CritterData.KHappy, 70f) + 8f, 0f, 100f)); } m_act = Act.Happy; m_timer = 1.3f; m_nview.InvokeRPC(ZNetView.Everybody, "CC_Fx", new object[1] { 1 }); } } private void RPC_Feed(long sender, string food) { if (m_nview.IsOwner()) { ZDO zDO = m_nview.GetZDO(); long now = CritterData.Now; zDO.Set(CritterData.KFed, now); zDO.Set(KAwake, now + 40); float num = (Food.IsFavourite(Species, food) ? 20f : 12f); zDO.Set(CritterData.KHappy, Mathf.Clamp(zDO.GetFloat(CritterData.KHappy, 70f) + num, 0f, 100f)); m_act = Act.Eat; m_timer = 3.2f; m_nview.InvokeRPC(ZNetView.Everybody, "CC_Fx", new object[1] { Food.IsFavourite(Species, food) ? 3 : 2 }); } } private void RPC_Fx(long sender, int fx) { PlayFx((Fx)fx); } private void PlayFx(Fx fx) { switch (fx) { case Fx.Pet: m_anim?.Hop(); PlayVoice(happy: true); Emote.Show(Emote.Kind.Heart, ((Component)this).transform, HeadHeight()); break; case Fx.Eat: case Fx.EatFav: m_anim?.Eat(3.2f); Play("eat_crunch", 0.8f); if (fx == Fx.EatFav) { Emote.Show(Emote.Kind.Heart, ((Component)this).transform, HeadHeight()); } break; case Fx.Born: Play("box_pop", 0.9f); Emote.Show(Emote.Kind.Star, ((Component)this).transform, HeadHeight()); m_anim?.Hop(); break; } } public void PlayVoice(bool happy) { if (Species == Species.GuineaPig) { Play((!happy) ? ((Random.value < 0.6f) ? "guinea_chut" : "guinea_wheek") : ((Random.value < 0.5f) ? "guinea_purr" : "guinea_wheek"), 0.8f); } else { Play(happy ? "hamster_happy" : ("hamster_squeak" + Random.Range(1, 4)), 0.75f); } } private void Play(string clip, float vol) { //IL_0037: Unknown result type (might be due to invalid IL or missing references) AudioClip val = Prefabs.Sound(clip); if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)m_audio)) { m_audio.pitch = Random.Range(0.93f, 1.08f) * ((((Component)this).transform.localScale.x < 0.9f) ? 1.18f : 1f); m_audio.PlayOneShot(val, vol * Plugin.Volume.Value); } } } internal static class VecExt { public static Vector3 Flat(this Vector3 v) { //IL_0000: 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_0011: Unknown result type (might be due to invalid IL or missing references) return new Vector3(v.x, 0f, v.z); } } public class CritterAnim : MonoBehaviour { public float Speed; public bool Sleeping; public bool Sad; public bool Held; private Transform m_body; private Transform m_head; private Transform m_earL; private Transform m_earR; private Transform m_eyeL; private Transform m_eyeR; private Transform[] m_feet = (Transform[])(object)new Transform[4]; private Vector3 m_bodyPos; private Vector3 m_headPos; private Vector3[] m_footPos = (Vector3[])(object)new Vector3[4]; private Quaternion m_earLRot; private Quaternion m_earRRot; private Vector3 m_eyeScale; private float m_phase; private float m_breath; private float m_sleepBlend; private float m_blinkT; private float m_nextBlink; private float m_earT; private float m_nextEar; private float m_hopT = -1f; private float m_eatT; private Quaternion m_look = Quaternion.identity; private Quaternion m_lookTarget = Quaternion.identity; private float m_nextLook; private float m_seed; private void Awake() { m_seed = Random.value * 100f; Rebuild(); } public void Rebuild() { //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_017f: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_01bb: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Unknown result type (might be due to invalid IL or missing references) //IL_01d9: Unknown result type (might be due to invalid IL or missing references) //IL_01de: Unknown result type (might be due to invalid IL or missing references) m_body = Find("Body"); m_head = Find("Head"); m_eyeL = Find("EyeL"); m_eyeR = Find("EyeR"); m_earL = Find("EarL"); m_earR = Find("EarR"); if (Object.op_Implicit((Object)(object)m_head)) { Transform[] array = (Transform[])(object)new Transform[4] { m_eyeL, m_eyeR, m_earL, m_earR }; foreach (Transform val in array) { if (Object.op_Implicit((Object)(object)val) && (Object)(object)val.parent != (Object)(object)m_head) { val.SetParent(m_head, true); } } } string[] array2 = new string[4] { "FootFL", "FootFR", "FootBL", "FootBR" }; for (int j = 0; j < 4; j++) { m_feet[j] = Find(array2[j]); if (Object.op_Implicit((Object)(object)m_feet[j])) { m_footPos[j] = m_feet[j].localPosition; } } if (Object.op_Implicit((Object)(object)m_body)) { m_bodyPos = m_body.localPosition; } if (Object.op_Implicit((Object)(object)m_head)) { m_headPos = m_head.localPosition; } if (Object.op_Implicit((Object)(object)m_earL)) { m_earLRot = m_earL.localRotation; } if (Object.op_Implicit((Object)(object)m_earR)) { m_earRRot = m_earR.localRotation; } if (Object.op_Implicit((Object)(object)m_eyeL)) { m_eyeScale = m_eyeL.localScale; } } private Transform Find(string n) { Transform[] componentsInChildren = ((Component)this).GetComponentsInChildren<Transform>(true); foreach (Transform val in componentsInChildren) { if (((Object)val).name == n) { return val; } } return null; } public void Hop() { m_hopT = 0f; } public void Eat(float seconds) { m_eatT = seconds; } private void LateUpdate() { //IL_01f5: Unknown result type (might be due to invalid IL or missing references) //IL_0231: Unknown result type (might be due to invalid IL or missing references) //IL_0242: Unknown result type (might be due to invalid IL or missing references) //IL_025e: Unknown result type (might be due to invalid IL or missing references) //IL_0263: Unknown result type (might be due to invalid IL or missing references) //IL_02e2: Unknown result type (might be due to invalid IL or missing references) //IL_02e8: Unknown result type (might be due to invalid IL or missing references) //IL_02f4: Unknown result type (might be due to invalid IL or missing references) //IL_02f9: Unknown result type (might be due to invalid IL or missing references) //IL_02d6: Unknown result type (might be due to invalid IL or missing references) //IL_02cf: Unknown result type (might be due to invalid IL or missing references) //IL_034e: Unknown result type (might be due to invalid IL or missing references) //IL_0353: Unknown result type (might be due to invalid IL or missing references) //IL_0382: Unknown result type (might be due to invalid IL or missing references) //IL_0387: Unknown result type (might be due to invalid IL or missing references) //IL_038f: Unknown result type (might be due to invalid IL or missing references) //IL_039d: Unknown result type (might be due to invalid IL or missing references) //IL_03a2: Unknown result type (might be due to invalid IL or missing references) //IL_03b3: Unknown result type (might be due to invalid IL or missing references) //IL_03de: Unknown result type (might be due to invalid IL or missing references) //IL_03e3: Unknown result type (might be due to invalid IL or missing references) //IL_02db: Unknown result type (might be due to invalid IL or missing references) //IL_04a3: Unknown result type (might be due to invalid IL or missing references) //IL_04bc: Unknown result type (might be due to invalid IL or missing references) //IL_04c1: Unknown result type (might be due to invalid IL or missing references) //IL_04df: Unknown result type (might be due to invalid IL or missing references) //IL_04fd: Unknown result type (might be due to invalid IL or missing references) //IL_0502: Unknown result type (might be due to invalid IL or missing references) //IL_05da: Unknown result type (might be due to invalid IL or missing references) //IL_05f4: Unknown result type (might be due to invalid IL or missing references) //IL_06b3: Unknown result type (might be due to invalid IL or missing references) //IL_06b9: Unknown result type (might be due to invalid IL or missing references) //IL_06be: Unknown result type (might be due to invalid IL or missing references) //IL_06d1: Unknown result type (might be due to invalid IL or missing references) //IL_06d6: Unknown result type (might be due to invalid IL or missing references) //IL_06d8: Unknown result type (might be due to invalid IL or missing references) //IL_06dd: Unknown result type (might be due to invalid IL or missing references) //IL_06df: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)m_body) || !Object.op_Implicit((Object)(object)m_head)) { return; } float deltaTime = Time.deltaTime; float num = Time.time + m_seed; m_sleepBlend = Mathf.MoveTowards(m_sleepBlend, Sleeping ? 1f : 0f, deltaTime * 1.5f); float sleepBlend = m_sleepBlend; float num2 = Mathf.Clamp01(Speed / 0.3f); if (m_eatT > 0f) { m_eatT -= deltaTime; } m_breath += deltaTime * Mathf.Lerp(3.2f, 1.4f, sleepBlend); float num3 = Mathf.Sin(m_breath) * Mathf.Lerp(0.025f, 0.04f, sleepBlend); m_phase += deltaTime * Mathf.Lerp(0f, 26f, num2) + (Held ? (deltaTime * 22f) : 0f); float num4 = Mathf.Abs(Mathf.Sin(m_phase)) * 0.006f * num2; float num5 = 0f; if (m_hopT >= 0f) { m_hopT += deltaTime; num5 = Mathf.Sin(Mathf.Clamp01(m_hopT / 0.35f) * (float)Math.PI) * 0.045f; if (m_hopT > 0.9f) { m_hopT = -1f; } else if (m_hopT > 0.45f) { num5 = Mathf.Sin(Mathf.Clamp01((m_hopT - 0.45f) / 0.3f) * (float)Math.PI) * 0.025f; } } Vector3 localScale = default(Vector3); ((Vector3)(ref localScale))..ctor(1f + sleepBlend * 0.08f - num3 * 0.4f, 1f - sleepBlend * 0.14f + num3, 1f + sleepBlend * 0.04f); m_body.localScale = localScale; float num6 = (Held ? (Mathf.Sin(num * 9f) * 7f) : 0f); m_body.localRotation = Quaternion.Euler(0f, 0f, num6); m_body.localPosition = m_bodyPos + new Vector3(0f, num4 + num5 - sleepBlend * 0.01f, 0f); if (Time.time > m_nextLook) { m_nextLook = Time.time + Random.Range(1.2f, 4f); m_lookTarget = ((Random.value < 0.35f) ? Quaternion.identity : Quaternion.Euler(Random.Range(-12f, 8f), Random.Range(-35f, 35f), Random.Range(-10f, 10f))); } m_look = Quaternion.Slerp(m_look, m_lookTarget, deltaTime * 5f); float num7 = 0f; if (m_eatT > 0f) { num7 = 18f + Mathf.Sin(num * 22f) * 6f; } if (Sad) { num7 += 10f; } num7 = Mathf.Lerp(num7, 16f, sleepBlend); Quaternion val = Quaternion.Slerp(m_look, Quaternion.identity, Mathf.Max(new float[3] { sleepBlend, num2 * 0.6f, (m_eatT > 0f) ? 1 : 0 })); m_head.localRotation = val * Quaternion.Euler(num7, 0f, 0f); m_head.localPosition = m_headPos + new Vector3(0f, num4 * 0.7f + num5 - sleepBlend * 0.025f + num3 * 0.01f, 0f); if (Time.time > m_nextEar) { m_nextEar = Time.time + Random.Range(2f, 6f); m_earT = 0.25f; } float num8 = ((m_earT > 0f) ? (Mathf.Sin(m_earT * 40f) * 12f) : 0f); m_earT -= deltaTime; float num9 = (Sad ? 30f : 0f) + sleepBlend * 25f - ((num5 > 0f) ? 15f : 0f); if (Object.op_Implicit((Object)(object)m_earL)) { m_earL.localRotation = m_earLRot * Quaternion.Euler((0f - num9) * 0.4f, 0f, 0f - num9 + num8); } if (Object.op_Implicit((Object)(object)m_earR)) { m_earR.localRotation = m_earRRot * Quaternion.Euler((0f - num9) * 0.4f, 0f, num9 - num8 * 0.5f); } if (Time.time > m_nextBlink) { m_nextBlink = Time.time + Random.Range(2.5f, 6f); m_blinkT = 0.14f; } m_blinkT -= deltaTime; float num10 = ((m_blinkT > 0f) ? 0.12f : 1f); num10 = Mathf.Min(num10, Mathf.Lerp(1f, 0.08f, sleepBlend)); if (m_hopT >= 0f) { num10 = Mathf.Min(num10, 0.35f); } Vector3 localScale2 = default(Vector3); ((Vector3)(ref localScale2))..ctor(m_eyeScale.x, m_eyeScale.y * num10, m_eyeScale.z); if (Object.op_Implicit((Object)(object)m_eyeL)) { m_eyeL.localScale = localScale2; } if (Object.op_Implicit((Object)(object)m_eyeR)) { m_eyeR.localScale = localScale2; } Vector3 val2 = default(Vector3); for (int i = 0; i < 4; i++) { if (Object.op_Implicit((Object)(object)m_feet[i])) { float num11 = m_phase + ((i == 0 || i == 3) ? 0f : ((float)Math.PI)); float num12 = (Held ? 1.2f : num2); ((Vector3)(ref val2))..ctor(0f, Mathf.Max(0f, Mathf.Sin(num11)) * 0.012f * num12, Mathf.Cos(num11) * 0.018f * num12); if (Held) { val2.y = Mathf.Sin(num11) * 0.01f; } Vector3 val3 = new Vector3(0f, 0.008f, (i < 2) ? (-0.015f) : 0.015f) * sleepBlend; m_feet[i].localPosition = m_footPos[i] + val2 + val3; } } } } public class CritterData { public Species Species; public int Coat; public string Name = ""; public long Born; public long Fed; public float Happy = 70f; public long HappyT; public long Bred; public const string ItemKey = "cozycritters"; public static readonly int KSpecies = StringExtensionMethods.GetStableHashCode("cc_species"); public static readonly int KCoat = StringExtensionMethods.GetStableHashCode("cc_coat"); public static readonly int KName = StringExtensionMethods.GetStableHashCode("cc_name"); public static readonly int KBorn = StringExtensionMethods.GetStableHashCode("cc_born"); public static readonly int KFed = StringExtensionMethods.GetStableHashCode("cc_fed"); public static readonly int KHappy = StringExtensionMethods.GetStableHashCode("cc_happy"); public static readonly int KHappyT = StringExtensionMethods.GetStableHashCode("cc_happyT"); public static readonly int KBred = StringExtensionMethods.GetStableHashCode("cc_bred"); public static long Now { get { if (!Object.op_Implicit((Object)(object)ZNet.instance)) { return 0L; } return (long)ZNet.instance.GetTimeSeconds(); } } public static float DayLen { get { if (!Object.op_Implicit((Object)(object)EnvMan.instance)) { return 1800f; } return Mathf.Max(60f, (float)EnvMan.instance.m_dayLengthSec); } } public float GrowDays => 1.5f; public static CritterData FromZDO(ZDO z) { return new CritterData { Species = (Species)z.GetInt(KSpecies, 0), Coat = z.GetInt(KCoat, 0), Name = z.GetString(KName, ""), Born = z.GetLong(KBorn, 0L), Fed = z.GetLong(KFed, 0L), Happy = z.GetFloat(KHappy, 70f), HappyT = z.GetLong(KHappyT, 0L), Bred = z.GetLong(KBred, 0L) }; } public void ToZDO(ZDO z) { z.Set(KSpecies, (int)Species, false); z.Set(KCoat, Coat, false); z.Set(KName, Name ?? ""); z.Set(KBorn, Born); z.Set(KFed, Fed); z.Set(KHappy, Happy); z.Set(KHappyT, HappyT); z.Set(KBred, Bred); } public string Serialize() { CultureInfo invariantCulture = CultureInfo.InvariantCulture; string[] obj = new string[9] { "1", null, null, null, null, null, null, null, null }; int species = (int)Species; obj[1] = species.ToString(invariantCulture); obj[2] = Coat.ToString(invariantCulture); obj[3] = Born.ToString(invariantCulture); obj[4] = Fed.ToString(invariantCulture); obj[5] = Happy.ToString("0.##", invariantCulture); obj[6] = HappyT.ToString(invariantCulture); obj[7] = Bred.ToString(invariantCulture); obj[8] = Uri.EscapeDataString(Name ?? ""); return string.Join("|", obj); } public static CritterData Parse(string s) { CritterData critterData = new CritterData(); if (string.IsNullOrEmpty(s)) { return critterData; } string[] array = s.Split('|'); CultureInfo invariantCulture = CultureInfo.InvariantCulture; try { critterData.Species = (Species)int.Parse(array[1], invariantCulture); critterData.Coat = int.Parse(array[2], invariantCulture); critterData.Born = long.Parse(array[3], invariantCulture); critterData.Fed = long.Parse(array[4], invariantCulture); critterData.Happy = float.Parse(array[5], invariantCulture); critterData.HappyT = long.Parse(array[6], invariantCulture); critterData.Bred = long.Parse(array[7], invariantCulture); critterData.Name = Uri.UnescapeDataString(array[8]); } catch (Exception ex) { Plugin.Log.LogWarning((object)("Could not read critter data '" + s + "': " + ex.Message)); } return critterData; } public float Fullness(long now) { return Mathf.Clamp01(1f - (float)(now - Fed) / DayLen); } public float Age01(long now) { return Mathf.Clamp01((float)(now - Born) / (DayLen * GrowDays)); } public bool IsAdult(long now) { return Age01(now) >= 1f; } public float Scale(long now) { return Mathf.Lerp(0.55f, 1f, Age01(now)); } public void TickHappiness(long now, bool hasFriends) { if (HappyT == 0L) { HappyT = now; } float num = (float)(now - HappyT) / DayLen; if (!(num <= 0f)) { bool num2 = Fullness(now) <= 0f; float num3 = (num2 ? 10f : (hasFriends ? 80f : 65f)); float num4 = (num2 ? 45f : 30f); float num5 = Mathf.Clamp(num3 - Happy, (0f - num4) * num, num4 * num); Happy = Mathf.Clamp(Happy + num5, 0f, 100f); HappyT = now; } } public void AddHappy(float v) { Happy = Mathf.Clamp(Happy + v, 0f, 100f); } } public class Emote : MonoBehaviour { public enum Kind { Heart, Zzz, Cloud, Star } private Transform m_follow; private float m_height; private float m_t; private float m_life; private Vector3 m_drift; public static void Show(Kind kind, Transform follow, float height) { //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) GameObject val = Prefabs.EmoteTemplate(kind); if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)follow)) { GameObject obj = Object.Instantiate<GameObject>(val); obj.SetActive(true); Emote emote = obj.AddComponent<Emote>(); emote.m_follow = follow; emote.m_height = height; emote.m_life = ((kind == Kind.Zzz) ? 2.4f : 1.6f); emote.m_drift = new Vector3(Random.Range(-0.05f, 0.05f), 0f, Random.Range(-0.05f, 0.05f)); emote.Place(0f); } } private void Place(float k) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: 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_010a: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)m_follow)) { Object.Destroy((Object)(object)((Component)this).gameObject); return; } ((Component)this).transform.position = m_follow.position + Vector3.up * (m_height + 0.06f + k * 0.18f) + m_drift * k; GameCamera instance = GameCamera.instance; if (Object.op_Implicit((Object)(object)instance)) { Vector3 val = ((Component)instance).transform.position - ((Component)this).transform.position; val.y = 0f; if (((Vector3)(ref val)).sqrMagnitude > 0.0001f) { ((Component)this).transform.rotation = Quaternion.LookRotation(val); } } float num = ((k < 0.15f) ? Mathf.SmoothStep(0f, 1.2f, k / 0.15f) : ((k > 0.75f) ? Mathf.Lerp(1f, 0f, (k - 0.75f) / 0.25f) : 1f)); ((Component)this).transform.localScale = Vector3.one * num * 1.3f; } private void LateUpdate() { m_t += Time.deltaTime; float num = m_t / m_life; if (num >= 1f) { Object.Destroy((Object)(object)((Component)this).gameObject); } else { Place(num); } } } public class GiftBoxOpening : MonoBehaviour { public static readonly int KOpener = StringExtensionMethods.GetStableHashCode("cc_opener"); private const float Duration = 2.8f; private ZNetView m_nview; private Transform m_box; private Transform m_lid; private Quaternion m_lidRest; private AudioSource m_audio; private float m_t; private bool m_popped; private bool m_spawned; private void Awake() { //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) m_nview = ((Component)this).GetComponent<ZNetView>(); Transform[] componentsInChildren = ((Component)this).GetComponentsInChildren<Transform>(true); foreach (Transform val in componentsInChildren) { if (((Object)val).name == "Box") { m_box = val; } if (((Object)val).name == "Lid") { m_lid = val; } } if (Object.op_Implicit((Object)(object)m_lid)) { m_lidRest = m_lid.localRotation; } m_audio = ((Component)this).GetComponent<AudioSource>(); AudioClip val2 = Prefabs.Sound("box_shake"); if (Object.op_Implicit((Object)(object)val2) && Object.op_Implicit((Object)(object)m_audio)) { m_audio.PlayOneShot(val2, 0.8f * Plugin.Volume.Value); } } private void Update() { //IL_0068: 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_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0148: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Unknown result type (might be due to invalid IL or missing references) //IL_0171: Unknown result type (might be due to invalid IL or missing references) //IL_026f: Unknown result type (might be due to invalid IL or missing references) //IL_027a: Unknown result type (might be due to invalid IL or missing references) //IL_0284: Unknown result type (might be due to invalid IL or missing references) //IL_0289: Unknown result type (might be due to invalid IL or missing references) //IL_028e: Unknown result type (might be due to invalid IL or missing references) //IL_0290: Unknown result type (might be due to invalid IL or missing references) //IL_0298: Unknown result type (might be due to invalid IL or missing references) m_t += Time.deltaTime; float num = Mathf.Clamp01(m_t / 2.8f); float num2 = Mathf.Lerp(2f, 12f, num * num); Quaternion localRotation = Quaternion.Euler(Mathf.Sin(m_t * 31f) * num2, 0f, Mathf.Sin(m_t * 27f + 1f) * num2); float num3 = Mathf.Max(0f, Mathf.Sin(m_t * 9f)) * 0.03f * num; if (Object.op_Implicit((Object)(object)m_box)) { m_box.localRotation = localRotation; m_box.localPosition = new Vector3(0f, num3, 0f); } if (m_t > 2.45f && !m_popped) { m_popped = true; AudioClip val = Prefabs.Sound("box_pop"); if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)m_audio)) { m_audio.PlayOneShot(val, 0.9f * Plugin.Volume.Value); } } if (m_popped && Object.op_Implicit((Object)(object)m_lid)) { m_lid.localRotation = Quaternion.Slerp(m_lid.localRotation, m_lidRest * Quaternion.Euler(-110f, 0f, 0f), Time.deltaTime * 14f); } if (m_t >= 2.8f && !m_spawned && Object.op_Implicit((Object)(object)m_nview) && m_nview.IsValid() && m_nview.IsOwner()) { m_spawned = true; Random random = new Random(Random.Range(int.MinValue, int.MaxValue)); Species species = ((!(random.NextDouble() < (double)Plugin.HamsterChance.Value)) ? Species.GuineaPig : Species.Hamster); long now = CritterData.Now; CritterData d = new CritterData { Species = species, Coat = Coats.Roll(species, random), Born = now - (long)(CritterData.DayLen * 2f), Fed = now, Happy = 75f, HappyT = now }; long namer = m_nview.GetZDO().GetLong(KOpener, 0L); Vector3 pos = ((Component)this).transform.position + ((Component)this).transform.forward * 0.05f; Critter.Spawn(d, pos, ((Component)this).transform.rotation, 0L, namer); ((MonoBehaviour)this).Invoke("Despawn", 0.6f); } } private void Despawn() { if (Object.op_Implicit((Object)(object)m_nview) && m_nview.IsValid() && m_nview.IsOwner()) { ZNetScene.instance.Destroy(((Component)this).gameObject); } } } [HarmonyPatch(typeof(Player), "ConsumeItem")] internal static class OpenGiftBox { private static bool Prefix(Player __instance, Inventory inventory, ItemData item, ref bool __result) { //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_006e: 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_0078: 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_0097: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_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_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) if (item == null || !Object.op_Implicit((Object)(object)item.m_dropPrefab) || ((Object)item.m_dropPrefab).name != "CC_GiftBox") { return true; } __result = false; if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer) { return false; } Vector3 val = ((Component)__instance).transform.position + ((Component)__instance).transform.forward * 1.1f; RaycastHit val2 = default(RaycastHit); if (Physics.Raycast(val + Vector3.up * 1.2f, Vector3.down, ref val2, 3f, Prefabs.GroundMask)) { val = ((RaycastHit)(ref val2)).point; inventory.RemoveOneItem(item); GameObject prefab = ZNetScene.instance.GetPrefab("CC_GiftBoxOpen"); Vector3 val3 = val; Vector3 val4 = ((Component)__instance).transform.forward.Flat(); Object.Instantiate<GameObject>(prefab, val3, Quaternion.LookRotation(-((Vector3)(ref val4)).normalized)).GetComponent<ZNetView>().GetZDO() .Set(GiftBoxOpening.KOpener, __instance.GetPlayerID()); __result = true; return false; } ((Character)__instance).Message((MessageType)2, "$cc_no_room", 0, (Sprite)null, false); return false; } } public static class Held { [HarmonyPatch(typeof(Humanoid), "StartAttack")] private static class NoAttackWithPet { private static bool Prefix(Humanoid __instance, bool secondaryAttack, ref bool __result) { Player val = (Player)(object)((__instance is Player) ? __instance : null); if (val == null || (Object)(object)val != (Object)(object)Player.m_localPlayer) { return true; } ItemData val2 = HeldItem(val); if (val2 == null) { return true; } __result = false; if (Time.time - s_lastPet < 0.8f) { return false; } s_lastPet = Time.time; CritterData critterData = ReadItem(val2); long now = CritterData.Now; critterData.TickHappiness(now, hasFriends: false); critterData.AddHappy(4f); WriteItem(val2, critterData); HeldVisual.Local?.Pet(); return false; } } [HarmonyPatch(typeof(ItemData), "GetTooltip", new Type[] { typeof(ItemData), typeof(int), typeof(bool), typeof(float), typeof(int), typeof(bool) })] private static class Tooltip { private static void Postfix(ItemData item, ref string __result) { if (IsCritterItem(item)) { CritterData critterData = ReadItem(item); long now = CritterData.Now; critterData.TickHappiness(now, hasFriends: false); Coat coat = Coats.Get(critterData.Species, critterData.Coat); string text = (string.IsNullOrEmpty(critterData.Name) ? "" : ("<color=#FFD38A>" + critterData.Name + "</color>\n")) + "$cc_coat_" + coat.Key + (critterData.IsAdult(now) ? "" : " · $cc_baby") + "\n" + Critter.Bars(critterData.Fullness(now), critterData.Happy) + "\n"; __result = Localization.instance.Localize(text) + __result; } } } private static float s_lastPet; public static bool IsCritterItem(ItemData item) { if (item != null && Object.op_Implicit((Object)(object)item.m_dropPrefab)) { return Prefabs.IsCritterItemPrefab(((Object)item.m_dropPrefab).name); } return false; } public static ItemData HeldItem(Player p) { if (!Object.op_Implicit((Object)(object)p)) { return null; } foreach (ItemData allItem in ((Humanoid)p).GetInventory().GetAllItems()) { if (allItem.m_equipped && IsCritterItem(allItem)) { return allItem; } } return null; } public static CritterData ReadItem(ItemData item) { item.m_customData.TryGetValue("cozycritters", out var value); CritterData critterData = CritterData.Parse(value); critterData.Species = Prefabs.SpeciesOfItem(((Object)item.m_dropPrefab).name); if (string.IsNullOrEmpty(value)) { critterData.Coat = item.m_variant; } return critterData; } public static void WriteItem(ItemData item, CritterData d) { item.m_customData["cozycritters"] = d.Serialize(); item.m_variant = d.Coat; } public static string DisplayName(ItemData item) { CritterData critterData = ReadItem(item); if (!string.IsNullOrEmpty(critterData.Name)) { return critterData.Name; } return Localization.instance.Localize(item.m_shared.m_name); } public static ItemData GiveItem(Player p, CritterData d) { Inventory inventory = ((Humanoid)p).GetInventory(); if (!inventory.HaveEmptySlot()) { return null; } ItemData val = inventory.AddItem(Prefabs.CritterItemName(d.Species), 1, 1, d.Coat, 0L, "", false, false); if (val == null) { return null; } WriteItem(val, d); ((Humanoid)p).EquipItem(val, true); return val; } } public class HeldVisual : MonoBehaviour { public Species Species; public static HeldVisual Local; private CritterAnim m_anim; private AudioSource m_audio; private float m_nextSqueak; private void Awake() { m_anim = ((Component)this).GetComponentInChildren<CritterAnim>(); if (Object.op_Implicit((Object)(object)m_anim)) { m_anim.Held = true; } m_audio = ((Component)this).gameObject.AddComponent<AudioSource>(); Prefabs.SetupAudio(m_audio); m_nextSqueak = Time.time + Random.Range(2f, 8f); ApplyOffset(); } private void Start() { if ((Object)(object)((Component)this).GetComponentInParent<Player>() == (Object)(object)Player.m_localPlayer && Object.op_Implicit((Object)(object)Player.m_localPlayer)) { Local = this; } ApplyOffset(); } private void OnDestroy() { if ((Object)(object)Local == (Object)(object)this) { Local = null; } } private void ApplyOffset() { //IL_0019: 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_0033: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)m_anim)) { ((Component)m_anim).transform.localPosition = Plugin.HeldOffset; ((Component)m_anim).transform.localRotation = Quaternion.Euler(Plugin.HeldRotation); } } public void Setup(int style) { Looks.ApplyCoat(Object.op_Implicit((Object)(object)m_anim) ? ((Component)m_anim).gameObject : ((Component)this).gameObject, Species, style); } public void Pet() { m_anim?.Hop(); Squeak(happy: true); Emote.Show(Emote.Kind.Heart, ((Component)this).transform, 0.25f); } private void Update() { if (Time.time > m_nextSqueak) { m_nextSqueak = Time.time + Random.Range(7f, 18f); Squeak(happy: false); } } private void Squeak(bool happy) { AudioClip val = Prefabs.Sound((Species != Species.GuineaPig) ? (happy ? "hamster_happy" : ("hamster_squeak" + Random.Range(1, 4))) : (happy ? "guinea_purr" : "guinea_wheek")); if (Object.op_Implicit((Object)(object)val)) { m_audio.PlayOneShot(val, 0.6f * Plugin.Volume.Value); } } } [HarmonyPatch(typeof(VisEquipment), "AttachItem")] internal static class HeldCoat { private static void Postfix(int variant, GameObject __result) { if (Object.op_Implicit((Object)(object)__result)) { HeldVisual componentInChildren = __result.GetComponentInChildren<HeldVisual>(); if (Object.op_Implicit((Object)(object)componentInChildren)) { componentInChildren.Setup(variant); } } } } public class CritterItemDrop : MonoBehaviour { private void Start() { //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: 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_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) ZNetView component = ((Component)this).GetComponent<ZNetView>(); ItemDrop component2 = ((Component)this).GetComponent<ItemDrop>(); if (!Object.op_Implicit((Object)(object)component) || !component.IsValid() || !component.IsOwner() || !Object.op_Implicit((Object)(object)component2)) { return; } CritterData d = Held.ReadItem(component2.m_itemData); Vector3 val = ((Component)this).transform.position; RaycastHit val2 = default(RaycastHit); if (Physics.Raycast(val + Vector3.up * 0.5f, Vector3.down, ref val2, 3f, Prefabs.GroundMask)) { val = ((RaycastHit)(ref val2)).point; } long cageId = 0L; foreach (Cage item in Cage.All) { if (Object.op_Implicit((Object)(object)item) && item.Contains(val) && item.Count() < 4) { cageId = item.Id; val = item.ClampInside(val); break; } } Critter.Spawn(d, val, Quaternion.Euler(0f, Random.Range(0f, 360f), 0f), cageId, 0L); ZNetScene.instance.Destroy(((Component)this).gameObject); } } public static class Looks { private static Material s_creatureBase; private static Material s_woodBase; private static Texture2D s_noise; private static readonly Dictionary<string, Material> s_cache = new Dictionary<string, Material>(); private static readonly Dictionary<string, Color> Fixed = new Dictionary<string, Color> { { "CC_Pink", new Color(0.95f, 0.62f, 0.66f) }, { "CC_Eye", new Color(0.04f, 0.035f, 0.045f) }, { "CC_White", Color.white }, { "CC_Straw", new Color(0.86f, 0.74f, 0.42f) }, { "CC_Paper", new Color(0.72f, 0.13f, 0.12f) }, { "CC_Ribbon", new Color(0.95f, 0.75f, 0.25f) }, { "CC_Iron", new Color(0.25f, 0.25f, 0.27f) }, { "CC_Heart", new Color(0.95f, 0.25f, 0.4f) }, { "CC_Cloud", new Color(0.55f, 0.58f, 0.65f) }, { "CC_Drop", new Color(0.35f, 0.6f, 0.95f) }, { "CC_Z", new Color(0.75f, 0.85f, 1f) }, { "CC_Star", new Color(1f, 0.85f, 0.3f) }, { "CC_Food", new Color(0.75f, 0.2f, 0.25f) }, { "CC_Food2", new Color(0.25f, 0.3f, 0.7f) }, { "CC_Seed", new Color(0.85f, 0.72f, 0.45f) } }; private static readonly Dictionary<Material, string> SlotNames = new Dictionary<Material, string>(); public static void Init() { //IL_01c1: 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_01cd: Unknown result type (might be due to invalid IL or missing references) //IL_01d4: Unknown result type (might be due to invalid IL or missing references) //IL_01e4: Expected O, but got Unknown //IL_021c: Unknown result type (might be due to invalid IL or missing references) //IL_0221: Unknown result type (might be due to invalid IL or missing references) s_creatureBase = Pick(new string[3] { "Boar", "Wolf", "Lox" }, (string sh) => sh.Contains("Creature"), (string m) => !m.Contains("tusk") && !m.Contains("eye")) ?? Pick(new string[1] { "Boar" }, (string sh) => !sh.Contains("Snow"), (string m) => !m.Contains("tusk")); s_woodBase = Pick(new string[5] { "wood_wall", "wood_floor", "piece_chair", "piece_table", "wood_pole" }, (string sh) => sh.Contains("Piece") && !sh.Contains("Snow"), (string m) => m.Contains("wood") && !m.Contains("snow")) ?? Pick(new string[2] { "wood_wall", "piece_chair" }, (string sh) => !sh.Contains("Snow"), (string m) => !m.Contains("snow")); Plugin.Log.LogInfo((object)("Materials: creature=" + Describe(s_creatureBase) + " wood=" + Describe(s_woodBase))); s_noise = new Texture2D(32, 32, (TextureFormat)4, false) { filterMode = (FilterMode)0, wrapMode = (TextureWrapMode)0, name = "cc_fur_noise" }; Random random = new Random(1234); Color[] array = (Color[])(object)new Color[1024]; for (int num = 0; num < array.Length; num++) { float num2 = 0.86f + (float)random.NextDouble() * 0.14f; array[num] = new Color(num2, num2, num2, 1f); } s_noise.SetPixels(array); s_noise.Apply(); } private static Material Pick(string[] prefabs, Func<string, bool> shaderOk, Func<string, bool> nameOk) { for (int i = 0; i < prefabs.Length; i++) { GameObject prefab = Cache.GetPrefab<GameObject>(prefabs[i]); if (!Object.op_Implicit((Object)(object)prefab)) { continue; } Renderer[] componentsInChildren = prefab.GetComponentsInChildren<Renderer>(true); for (int j = 0; j < componentsInChildren.Length; j++) { Material[] sharedMaterials = componentsInChildren[j].sharedMaterials; foreach (Material val in sharedMaterials) { if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.shader) && shaderOk(((Object)val.shader).name) && nameOk(((Object)val).name.ToLowerInvariant())) { return val; } } } } return null; } private static string Describe(Material m) { if (!Object.op_Implicit((Object)(object)m)) { return "none"; } Shader shader = m.shader; List<string> list = new List<string>(); for (int i = 0; i < shader.GetPropertyCount(); i++) { list.Add(shader.GetPropertyName(i)); } return ((Object)m).name + " [" + ((Object)shader).name + "] {" + string.Join(",", list) + "}"; } private static string Clean(string matName) { int num = matName.IndexOf(' '); if (num <= 0) { return matName; } return matName.Substring(0, num); } private static Material Make(string key, Material template, Color c, bool keepTexture) { //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: 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: Expected O, but got Unknown //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Expected O, but got Unknown //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) if (s_cache.TryGetValue(key, out var value) && Object.op_Implicit((Object)(object)value)) { return value; } if (Object.op_Implicit((Object)(object)template)) { value = new Material(template) { name = key };