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 AdminAnimals v0.1.1
BepInEx/plugins/AdminAnimals/AdminAnimals.dll
Decompiled 2 weeks 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.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using AdminAnimals.Core; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using HarmonyLib; using Jotunn.Utils; using Microsoft.CodeAnalysis; using Splatform; using TMPro; using UnityEngine; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("AdminAnimals")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.1.1.0")] [assembly: AssemblyInformationalVersion("0.1.1")] [assembly: AssemblyProduct("AdminAnimals")] [assembly: AssemblyTitle("AdminAnimals")] [assembly: AssemblyVersion("0.1.1.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace AdminAnimals { internal sealed class AnimalForm : MonoBehaviour { private sealed class AnimatorBinding { private readonly Animator animator; private readonly AnimatorControllerParameter[] parameters; internal AnimatorBinding(Animator a) { animator = a; parameters = a.parameters; } internal void Update(Player p) { //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_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Invalid comparison between Unknown and I4 //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Invalid comparison between Unknown and I4 //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) Vector3 val = ((Component)p).transform.InverseTransformDirection(((Character)p).GetVelocity()); AnimatorControllerParameter[] array = parameters; foreach (AnimatorControllerParameter val2 in array) { if ((int)val2.type == 1) { if (val2.name == "forward_speed") { animator.SetFloat(val2.nameHash, val.z); } else if (val2.name == "sideway_speed") { animator.SetFloat(val2.nameHash, val.x); } else if (val2.name == "speed") { Animator obj = animator; int nameHash = val2.nameHash; Vector2 val3 = new Vector2(val.x, val.z); obj.SetFloat(nameHash, ((Vector2)(ref val3)).magnitude); } } else if ((int)val2.type == 4) { if (val2.name == "onGround") { animator.SetBool(val2.nameHash, ((Character)p).IsOnGround()); } else if (val2.name == "inWater") { animator.SetBool(val2.nameHash, ((Character)p).IsSwimming()); } else if (val2.name == "flying" || val2.name == "dead" || val2.name == "alert" || val2.name == "sleeping") { animator.SetBool(val2.nameHash, false); } } } } } private Player player; private GameObject root; private string animal; private readonly Dictionary<Renderer, bool> hidden = new Dictionary<Renderer, bool>(); private readonly Dictionary<Light, bool> lights = new Dictionary<Light, bool>(); private readonly List<AnimatorBinding> animators = new List<AnimatorBinding>(); private float nextScan; private float nextFailure; private bool Suspended { get { if (!((Character)player).IsDead() && !((Character)player).IsTeleporting() && !((Character)player).InCutscene()) { return ((Character)player).InIntro(); } return true; } } internal static AnimalForm For(Player p) { return ((Component)p).GetComponent<AnimalForm>() ?? ((Component)p).gameObject.AddComponent<AnimalForm>(); } private void Awake() { player = ((Component)this).GetComponent<Player>(); } private void LateUpdate() { FormRecord formRecord = Plugin.Instance?.Network?.Get((Character)(object)player); AnimalSpec animalSpec = ((formRecord == null) ? null : Animals.Find(formRecord.Animal)); if (animalSpec == null || animalSpec.Bird || Suspended) { End(!Suspended); return; } if (Object.op_Implicit((Object)(object)root) && animal != animalSpec.Name) { End(effect: true); } if (!Object.op_Implicit((Object)(object)root)) { if (Time.unscaledTime < nextFailure) { return; } try { if (!Begin(animalSpec)) { nextFailure = Time.unscaledTime + 2f; return; } } catch (Exception e) { End(effect: false); nextFailure = Time.unscaledTime + 2f; Plugin.Instance.Error("Animal visual could not start; lock retained", e); return; } } HidePlayer(); foreach (AnimatorBinding animator in animators) { animator.Update(player); } } private bool Begin(AnimalSpec spec) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Expected O, but got Unknown //IL_022e: Unknown result type (might be due to invalid IL or missing references) //IL_0233: Unknown result type (might be due to invalid IL or missing references) //IL_023d: 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) if (!spec.Available()) { return false; } root = new GameObject("AdminAnimals " + spec.Name); root.SetActive(false); root.transform.SetParent(((Component)player).transform, false); GameObject val = Object.Instantiate<GameObject>(spec.GetGroundVisual(), root.transform, false); foreach (MonoBehaviour item in val.GetComponentsInChildren<MonoBehaviour>(true).AsEnumerable().Reverse()) { Object.DestroyImmediate((Object)(object)item); } Collider[] componentsInChildren = val.GetComponentsInChildren<Collider>(true); for (int i = 0; i < componentsInChildren.Length; i++) { Object.DestroyImmediate((Object)(object)componentsInChildren[i]); } Rigidbody[] componentsInChildren2 = val.GetComponentsInChildren<Rigidbody>(true); for (int i = 0; i < componentsInChildren2.Length; i++) { Object.DestroyImmediate((Object)(object)componentsInChildren2[i]); } AudioSource[] componentsInChildren3 = val.GetComponentsInChildren<AudioSource>(true); for (int i = 0; i < componentsInChildren3.Length; i++) { Object.DestroyImmediate((Object)(object)componentsInChildren3[i]); } if (val.GetComponentsInChildren<MonoBehaviour>(true).Length != 0) { throw new InvalidOperationException("Animal visual still contains gameplay scripts; refusing activation."); } LODGroup[] componentsInChildren4 = val.GetComponentsInChildren<LODGroup>(true); foreach (LODGroup obj in componentsInChildren4) { obj.RecalculateBounds(); obj.ForceLOD(0); } Renderer[] componentsInChildren5 = val.GetComponentsInChildren<Renderer>(true); foreach (Renderer obj2 in componentsInChildren5) { obj2.enabled = true; obj2.forceRenderingOff = false; } Animator[] componentsInChildren6 = val.GetComponentsInChildren<Animator>(true); foreach (Animator obj3 in componentsInChildren6) { ((Behaviour)obj3).enabled = true; obj3.fireEvents = false; } val.SetActive(true); root.SetActive(true); if (!val.GetComponentsInChildren<Renderer>().Any((Renderer r) => r.enabled && ((Component)r).gameObject.activeInHierarchy)) { throw new InvalidOperationException("Animal visual has no active renderer; keeping the player visible."); } componentsInChildren6 = val.GetComponentsInChildren<Animator>(true); foreach (Animator a in componentsInChildren6) { animators.Add(new AnimatorBinding(a)); } animal = spec.Name; nextScan = 0f; HidePlayer(); ForcedBird.Puff(((Component)player).transform.position + Vector3.up * 0.5f); return true; } private void HidePlayer() { if (Time.unscaledTime >= nextScan) { nextScan = Time.unscaledTime + 0.5f; Renderer[] componentsInChildren = ((Component)player).GetComponentsInChildren<Renderer>(true); foreach (Renderer val in componentsInChildren) { if (!((Component)val).transform.IsChildOf(root.transform) && !hidden.ContainsKey(val)) { hidden.Add(val, val.forceRenderingOff); } } Light[] componentsInChildren2 = ((Component)player).GetComponentsInChildren<Light>(true); foreach (Light val2 in componentsInChildren2) { if (!((Component)val2).transform.IsChildOf(root.transform) && !lights.ContainsKey(val2)) { lights.Add(val2, ((Behaviour)val2).enabled); } } componentsInChildren = hidden.Keys.Where((Renderer r) => !Object.op_Implicit((Object)(object)r)).ToArray(); foreach (Renderer key in componentsInChildren) { hidden.Remove(key); } componentsInChildren2 = lights.Keys.Where((Light l) => !Object.op_Implicit((Object)(object)l)).ToArray(); foreach (Light key2 in componentsInChildren2) { lights.Remove(key2); } } foreach (Renderer key3 in hidden.Keys) { if (Object.op_Implicit((Object)(object)key3)) { key3.forceRenderingOff = true; } } foreach (Light key4 in lights.Keys) { if (Object.op_Implicit((Object)(object)key4)) { ((Behaviour)key4).enabled = false; } } } internal void End(bool effect) { //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_00d8: 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) if (!Object.op_Implicit((Object)(object)root)) { return; } foreach (KeyValuePair<Renderer, bool> item in hidden) { if (Object.op_Implicit((Object)(object)item.Key)) { item.Key.forceRenderingOff = item.Value; } } foreach (KeyValuePair<Light, bool> light in lights) { if (Object.op_Implicit((Object)(object)light.Key)) { ((Behaviour)light.Key).enabled = light.Value; } } if (effect && !((Character)player).IsDead()) { ForcedBird.Puff(((Component)player).transform.position + Vector3.up * 0.5f); } root.SetActive(false); Object.Destroy((Object)(object)root); root = null; animal = null; hidden.Clear(); lights.Clear(); animators.Clear(); } private void OnDestroy() { End(effect: false); } } internal sealed class AnimalNetwork { private const string Query = "AdminAnimals_Query_v1"; private const string Request = "AdminAnimals_Command_v1"; private const string State = "AdminAnimals_State_v1"; private const string Reply = "AdminAnimals_Reply_v1"; private const string Sound = "AdminAnimals_Sound_v1"; private const string PlaySound = "AdminAnimals_PlaySound_v1"; private readonly HashSet<ZRpc> registered = new HashSet<ZRpc>(); private readonly Dictionary<ZRpc, float> requests = new Dictionary<ZRpc, float>(); private readonly Dictionary<long, ZDOID> bodies = new Dictionary<long, ZDOID>(); private readonly Dictionary<long, float> soundTimes = new Dictionary<long, float>(); private readonly FormStore store = new FormStore(); private Dictionary<ZDOID, FormRecord> visible = new Dictionary<ZDOID, FormRecord>(); private ZNet session; private string savePath; private string loadError; private float nextTick; private float nextSnapshot; private float nextQuery; private long revision; private long receivedRevision = -1L; private ZDOID localBody; private bool ready; private bool admin; private Terminal output; private static long Self => ZNet.GetUID(); internal bool Ready => ready; internal FormRecord Get(Character c) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)c) || !(c is Player) || !visible.TryGetValue(c.GetZDOID(), out var value)) { return null; } return value; } internal bool Locked(Character c) { return Get(c) != null; } internal bool Restricted(Character c) { FormRecord formRecord = Get(c); if (formRecord == null) { return false; } return !formRecord.Tools; } internal bool IsBird(Character c) { FormRecord formRecord = Get(c); if (formRecord != null) { AnimalSpec animalSpec = Animals.Find(formRecord.Animal); if (animalSpec != null && animalSpec.Bird && !c.IsDead() && !c.IsTeleporting() && !c.InCutscene() && !c.IsAttached() && !c.IsSwimming()) { return !c.IsDebugFlying(); } } return false; } internal bool PeerLocked(long uid) { if (Object.op_Implicit((Object)(object)session) && session.IsServer()) { return store.Records.ContainsKey(Account(uid)); } return false; } private static ZNetPeer Peer(ZRpc rpc) { return ((IEnumerable<ZNetPeer>)ZNet.instance.GetPeers()).FirstOrDefault((Func<ZNetPeer, bool>)((ZNetPeer p) => p.IsReady() && p.m_rpc == rpc)); } private static string Account(long uid) { if (uid == Self) { return ((object)Unsafe.As<PlatformUserID, PlatformUserID>(ref UserInfo.GetLocalUser().UserId)/*cast due to .constrained prefix*/).ToString(); } ZNetPeer peer = ZNet.instance.GetPeer(uid); object obj; if (peer == null) { obj = null; } else { ISocket socket = peer.m_socket; obj = ((socket != null) ? socket.GetHostName() : null); } if (obj == null) { obj = ""; } return (string)obj; } internal static bool IsAdmin(long uid) { if (!Object.op_Implicit((Object)(object)ZNet.instance) || !ZNet.instance.IsServer()) { return false; } if (uid == Self) { return true; } ZNetPeer peer = ZNet.instance.GetPeer(uid); if (peer != null && peer.IsReady() && peer.m_socket != null) { return ZNet.instance.IsAdmin(peer.m_socket.GetHostName()); } return false; } private static ZDOID Body(long uid) { //IL_0028: 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_0017: Unknown result type (might be due to invalid IL or missing references) if (uid != Self) { return ZNet.instance.GetPeer(uid)?.m_characterID ?? ZDOID.None; } return ZNet.instance.LocalPlayerCharacterID; } internal void Update() { //IL_0186: Unknown result type (might be due to invalid IL or missing references) //IL_0190: Expected O, but got Unknown //IL_01fa: Unknown result type (might be due to invalid IL or missing references) //IL_0204: Expected O, but got Unknown //IL_04cf: Unknown result type (might be due to invalid IL or missing references) //IL_04d4: Unknown result type (might be due to invalid IL or missing references) //IL_02be: 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_04fa: Unknown result type (might be due to invalid IL or missing references) //IL_04e7: Unknown result type (might be due to invalid IL or missing references) //IL_04e9: Unknown result type (might be due to invalid IL or missing references) //IL_02c3: Unknown result type (might be due to invalid IL or missing references) //IL_02c4: Unknown result type (might be due to invalid IL or missing references) //IL_02c6: Unknown result type (might be due to invalid IL or missing references) //IL_02d3: Unknown result type (might be due to invalid IL or missing references) //IL_02d4: 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_02fa: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)ZNet.instance)) { if (Object.op_Implicit((Object)(object)session)) { Reset(); } return; } if ((Object)(object)session != (Object)(object)ZNet.instance) { Reset(); session = ZNet.instance; if (session.IsServer()) { savePath = Path.Combine(Paths.ConfigPath, "AdminAnimals", "world-" + session.GetWorldUID().ToString(CultureInfo.InvariantCulture) + ".dat"); try { store.Load(savePath); if (store.Prune(DateTime.UtcNow.Ticks)) { store.Save(savePath); } } catch (Exception ex) { loadError = ex.Message; Plugin.Instance.Error("Animal state could not load; commands disabled to preserve saved data", ex); } } } if (Time.unscaledTime < nextTick) { return; } nextTick = Time.unscaledTime + 0.25f; List<ZNetPeer> peers = session.GetPeers(); foreach (ZNetPeer item in peers) { if (item.IsReady() && item.m_rpc != null && registered.Add(item.m_rpc)) { item.m_rpc.Register("AdminAnimals_Query_v1", new Method(OnQuery)); item.m_rpc.Register<ZPackage>("AdminAnimals_Command_v1", (Action<ZRpc, ZPackage>)OnRequest); item.m_rpc.Register<ZPackage>("AdminAnimals_State_v1", (Action<ZRpc, ZPackage>)OnState); item.m_rpc.Register<string>("AdminAnimals_Reply_v1", (Action<ZRpc, string>)OnReply); item.m_rpc.Register("AdminAnimals_Sound_v1", new Method(OnSound)); item.m_rpc.Register<ZDOID>("AdminAnimals_PlaySound_v1", (Action<ZRpc, ZDOID>)OnPlaySound); } } ZRpc[] array = registered.Where((ZRpc r) => !peers.Any((ZNetPeer p) => p.m_rpc == r)).ToArray(); foreach (ZRpc val in array) { registered.Remove(val); requests.Remove(val); } ZDOID val2 = (Object.op_Implicit((Object)(object)Player.m_localPlayer) ? ((Character)Player.m_localPlayer).GetZDOID() : ZDOID.None); if (val2 != localBody) { localBody = val2; nextQuery = 0f; } if (!session.IsServer()) { if ((!ready || val2 != ZDOID.None) && Time.unscaledTime >= nextQuery) { nextQuery = Time.unscaledTime + (ready ? 20f : 1f); ZNetPeer serverPeer = session.GetServerPeer(); if (serverPeer != null) { serverPeer.m_rpc.Invoke("AdminAnimals_Query_v1", Array.Empty<object>()); } } return; } bool flag = false; if (loadError == null) { FormRecord[] array2 = store.Records.Values.Where((FormRecord r) => r.Expired(DateTime.UtcNow.Ticks)).ToArray(); if (array2.Length != 0) { FormRecord[] array3 = array2; foreach (FormRecord formRecord in array3) { store.Records.Remove(formRecord.Account); } try { store.Save(savePath); flag = true; } catch (Exception e) { array3 = array2; foreach (FormRecord formRecord2 in array3) { store.Records[formRecord2.Account] = formRecord2; } Plugin.Instance.Error("Expiry save failed; will retry", e); } } } List<long> online = (from p in peers where p.IsReady() select p.m_uid).ToList(); if (Object.op_Implicit((Object)(object)Player.m_localPlayer)) { online.Add(Self); } foreach (long item2 in online) { ZDOID val3 = Body(item2); if (!bodies.TryGetValue(item2, out var value) || val3 != value) { bodies[item2] = val3; flag = true; } } long[] array4 = bodies.Keys.Where((long u) => !online.Contains(u)).ToArray(); foreach (long key in array4) { bodies.Remove(key); soundTimes.Remove(key); flag = true; } if (flag) { revision++; } if (flag || Time.unscaledTime >= nextSnapshot) { Publish(); } } private void Reset() { //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) visible.Clear(); store.Records.Clear(); registered.Clear(); requests.Clear(); bodies.Clear(); soundTimes.Clear(); session = null; ready = (admin = false); loadError = (savePath = null); revision = 0L; receivedRevision = -1L; nextTick = (nextSnapshot = (nextQuery = 0f)); localBody = ZDOID.None; output = null; } internal void Stop() { Reset(); } private bool Throttle(ZRpc rpc) { if (requests.TryGetValue(rpc, out var value) && Time.unscaledTime - value < 0.15f) { return true; } requests[rpc] = Time.unscaledTime; return false; } private void OnQuery(ZRpc rpc) { if (session.IsServer()) { ZNetPeer val = Peer(rpc); if (val != null && !Throttle(rpc)) { SendState(val.m_uid); } } } private void OnRequest(ZRpc rpc, ZPackage packet) { if (!session.IsServer()) { return; } ZNetPeer val = Peer(rpc); if (val == null || Throttle(rpc)) { return; } try { if (packet.Size() > 2048) { throw new ArgumentException("Command is too long."); } bool tools = packet.ReadBool(); int num = packet.ReadInt(); if (num < 1 || num > 3) { throw new ArgumentException("Invalid arguments."); } string[] array = new string[num]; for (int i = 0; i < num; i++) { array[i] = packet.ReadString(); if (array[i].Length > 256) { throw new ArgumentException("Argument is too long."); } } if (packet.GetPos() != packet.Size()) { throw new ArgumentException("Invalid command packet."); } Answer(val.m_uid, Execute(val.m_uid, array, tools)); } catch (Exception ex) { Answer(val.m_uid, ex.Message); } } internal void Command(string[] args, bool tools, Terminal terminal) { //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Expected O, but got Unknown output = terminal; if (!Object.op_Implicit((Object)(object)session)) { terminal.AddString("Join a world first."); return; } if (session.IsServer()) { terminal.AddString(Execute(Self, args, tools)); return; } if (!ready) { terminal.AddString("Waiting for the server's animal state."); return; } if (!admin) { terminal.AddString("The server has not granted you admin permission."); return; } ZPackage val = new ZPackage(); val.Write(tools); val.Write(args.Length); foreach (string text in args) { val.Write(text); } ZNetPeer serverPeer = session.GetServerPeer(); if (serverPeer != null) { serverPeer.m_rpc.Invoke("AdminAnimals_Command_v1", new object[1] { val }); } } private string Execute(long sender, string[] args, bool tools) { //IL_03ea: Unknown result type (might be due to invalid IL or missing references) //IL_03ef: Unknown result type (might be due to invalid IL or missing references) if (!IsAdmin(sender)) { return "Only the server host or a server admin may change animal forms."; } if (args.Length == 1 && args[0].Equals("list", StringComparison.OrdinalIgnoreCase)) { return "Available: " + string.Join(", ", from a in Animals.All where a.Available() select a.Name) + ". Aliases: bird, rabbit. human releases; random chooses an available form."; } if (args.Length == 1 && args[0].Equals("status", StringComparison.OrdinalIgnoreCase)) { if (store.Records.Count != 0) { return string.Join("\n", store.Records.Values.Select((FormRecord r) => r.Account + ": " + r.Animal + (r.Tools ? " (tools enabled)" : " (restricted)") + ((r.ExpiresUtcTicks == 0L) ? " until admin release" : (" expires " + new DateTime(r.ExpiresUtcTicks, DateTimeKind.Utc).ToString("u"))))); } return "No forced forms."; } if (loadError != null) { return "Saved animal state could not load: " + loadError + ". Repair the state file before changing forms."; } if (args.Length == 1 && args[0].Equals("clearall", StringComparison.OrdinalIgnoreCase)) { FormRecord[] array = store.Records.Values.ToArray(); store.Records.Clear(); try { store.Save(savePath); } catch { FormRecord[] array2 = array; foreach (FormRecord formRecord in array2) { store.Records[formRecord.Account] = formRecord; } throw; } revision++; Publish(); Plugin.Instance.Audit("Admin " + Account(sender) + " released all animal forms."); return "All forced forms released."; } if (args.Length < 2 || args.Length > 3) { return "Use: animalform/animalplay \"Player Name\" animal [seconds]."; } if (!Rules.Duration((args.Length == 3) ? args[2] : null, out var seconds)) { return "Duration must be 0–31536000 seconds. Omitted or 0 means until admin release."; } List<long> list = (from p in session.GetPeers() where p.IsReady() && (p.m_playerName.Equals(args[0], StringComparison.OrdinalIgnoreCase) || AccountMatches(Account(p.m_uid), args[0])) select p.m_uid).ToList(); if (Object.op_Implicit((Object)(object)Player.m_localPlayer) && (Player.m_localPlayer.GetPlayerName().Equals(args[0], StringComparison.OrdinalIgnoreCase) || AccountMatches(Account(Self), args[0]))) { list.Add(Self); } bool flag = args[1].Equals("human", StringComparison.OrdinalIgnoreCase); string text; if (list.Count == 0 && flag && store.Records.ContainsKey(args[0])) { text = args[0]; } else { if (list.Count != 1) { if (list.Count != 0) { return "Multiple players match. Use the full account ID shown by animalform status."; } return "No connected player matches that name or account ID."; } text = Account(list[0]); } if (string.IsNullOrWhiteSpace(text)) { return "The target's authenticated account ID is unavailable."; } AnimalSpec animalSpec = null; if (!flag) { if (args[1].Equals("random", StringComparison.OrdinalIgnoreCase)) { AnimalSpec[] array3 = Animals.All.Where((AnimalSpec a) => a.Available()).ToArray(); if (array3.Length != 0) { animalSpec = array3[Random.Range(0, array3.Length)]; } } else { animalSpec = Animals.Find(args[1]); } if (animalSpec == null || !animalSpec.Available()) { return "Animal is unsupported or unavailable. Use animalform list."; } if (Body(list[0]) == ZDOID.None) { return "The target's player body is not ready. Retry after they spawn."; } } store.Records.TryGetValue(text, out var value); if (flag) { store.Records.Remove(text); } else { store.Records[text] = new FormRecord { Account = text, Animal = animalSpec.Name, Tools = tools, ExpiresUtcTicks = Rules.Expiry(DateTime.UtcNow.Ticks, seconds) }; } try { store.Save(savePath); } catch { if (value == null) { store.Records.Remove(text); } else { store.Records[text] = value; } throw; } revision++; Publish(); string text2 = (flag ? ("Released " + args[0] + ".") : (args[0] + " is now " + animalSpec.Name + (tools ? " with normal tool use" : " with tools disabled") + ((seconds == 0.0) ? " until admin release." : (" for " + seconds.ToString(CultureInfo.InvariantCulture) + " seconds.")))); Plugin.Instance.Audit("Admin " + Account(sender) + ": " + text2); return text2; } private static bool AccountMatches(string account, string input) { if (!account.Equals(input, StringComparison.OrdinalIgnoreCase)) { if (account.StartsWith("Steam_", StringComparison.OrdinalIgnoreCase)) { return account.Substring(6).Equals(input, StringComparison.Ordinal); } return false; } return true; } private void Answer(long uid, string message) { if (uid == Self) { Terminal obj = output; if (obj != null) { obj.AddString(message); } return; } ZNetPeer peer = session.GetPeer(uid); if (peer != null) { peer.m_rpc.Invoke("AdminAnimals_Reply_v1", new object[1] { message }); } } private void OnReply(ZRpc rpc, string message) { if (!session.IsServer() && session.GetServerPeer()?.m_rpc == rpc) { if (Object.op_Implicit((Object)(object)output)) { output.AddString(message); } else { Plugin.Instance.Message(message); } } } private void Publish() { nextSnapshot = Time.unscaledTime + 20f; foreach (ZNetPeer peer in session.GetPeers()) { if (peer.IsReady()) { SendState(peer.m_uid); } } if (Object.op_Implicit((Object)(object)Player.m_localPlayer)) { SendState(Self); } } private void SendState(long recipient) { //IL_002d: 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_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Expected O, but got Unknown //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_0061: 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_0123: Unknown result type (might be due to invalid IL or missing references) List<KeyValuePair<ZDOID, FormRecord>> list = new List<KeyValuePair<ZDOID, FormRecord>>(); foreach (ZNetPeer peer2 in session.GetPeers()) { if (peer2.IsReady() && peer2.m_characterID != ZDOID.None && store.Records.TryGetValue(Account(peer2.m_uid), out var value)) { list.Add(new KeyValuePair<ZDOID, FormRecord>(peer2.m_characterID, value)); } } if (Object.op_Implicit((Object)(object)Player.m_localPlayer) && session.LocalPlayerCharacterID != ZDOID.None && store.Records.TryGetValue(Account(Self), out var value2)) { list.Add(new KeyValuePair<ZDOID, FormRecord>(session.LocalPlayerCharacterID, value2)); } ZPackage val = new ZPackage(); val.Write(revision); val.Write(IsAdmin(recipient)); val.Write(list.Count); foreach (KeyValuePair<ZDOID, FormRecord> item in list) { val.Write(item.Key); val.Write(item.Value.Animal); val.Write(item.Value.Tools); val.Write(item.Value.ExpiresUtcTicks); } val.SetPos(0); if (recipient == Self) { Receive(val); return; } ZNetPeer peer = session.GetPeer(recipient); if (peer != null) { peer.m_rpc.Invoke("AdminAnimals_State_v1", new object[1] { val }); } } private void OnState(ZRpc rpc, ZPackage packet) { if (!session.IsServer() && session.GetServerPeer()?.m_rpc == rpc) { Receive(packet); } } private void Receive(ZPackage packet) { //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_007d: 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_009b: Unknown result type (might be due to invalid IL or missing references) try { if (packet.Size() > 131072) { throw new InvalidDataException("Oversized snapshot."); } long num = packet.ReadLong(); bool flag = packet.ReadBool(); int num2 = packet.ReadInt(); if (num < receivedRevision) { return; } if (num2 < 0 || num2 > 1024) { throw new InvalidDataException("Invalid snapshot count."); } Dictionary<ZDOID, FormRecord> dictionary = new Dictionary<ZDOID, FormRecord>(); for (int i = 0; i < num2; i++) { ZDOID val = packet.ReadZDOID(); string text = packet.ReadString(); bool tools = packet.ReadBool(); long num3 = packet.ReadLong(); if (val == ZDOID.None || Animals.Find(text) == null || num3 < 0 || !dictionary.TryAdd(val, new FormRecord { Animal = text, Tools = tools, ExpiresUtcTicks = num3 })) { throw new InvalidDataException("Invalid form state."); } } if (packet.GetPos() != packet.Size()) { throw new InvalidDataException("Trailing snapshot data."); } visible = dictionary; receivedRevision = num; admin = flag; ready = true; if (!((Object)(object)Plugin.Instance != (Object)null)) { return; } foreach (Character allCharacter in Character.GetAllCharacters()) { Player val2 = (Player)(object)((allCharacter is Player) ? allCharacter : null); if (val2 != null && Get(allCharacter) != null) { Prepare(val2); } } } catch (Exception e) { Plugin.Instance?.Error("Animal snapshot rejected", e); } } internal void Prepare(Player player) { FormRecord formRecord = Get((Character)(object)player); if (formRecord == null) { return; } Plugin.Instance.Birds.Yield(player); AnimalSpec animalSpec = Animals.Find(formRecord.Animal); if (animalSpec != null && animalSpec.Bird) { ((Component)player).GetComponent<AnimalForm>()?.End(effect: false); ForcedBird.For(player); return; } ForcedBird component = ((Component)player).GetComponent<ForcedBird>(); if (!Object.op_Implicit((Object)(object)component) || component.End(effect: false)) { AnimalForm.For(player); } } internal void HideMap(List<PlayerInfo> players) { //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) for (int num = players.Count - 1; num >= 0; num--) { if (visible.ContainsKey(players[num].m_characterID)) { players.RemoveAt(num); } } } internal void RequestSound() { if (!Object.op_Implicit((Object)(object)session) || !Object.op_Implicit((Object)(object)Player.m_localPlayer) || !Locked((Character)(object)Player.m_localPlayer)) { Plugin.Instance.Message("You are not in an animal form."); return; } if (session.IsServer()) { SoundFor(Self); return; } ZNetPeer serverPeer = session.GetServerPeer(); if (serverPeer != null) { serverPeer.m_rpc.Invoke("AdminAnimals_Sound_v1", Array.Empty<object>()); } } private void OnSound(ZRpc rpc) { if (session.IsServer()) { ZNetPeer val = Peer(rpc); if (val != null) { SoundFor(val.m_uid); } } } private void SoundFor(long uid) { //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0076: 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) if (!PeerLocked(uid) || (soundTimes.TryGetValue(uid, out var value) && Time.unscaledTime - value < 3f)) { return; } soundTimes[uid] = Time.unscaledTime; ZDOID val = Body(uid); foreach (ZNetPeer peer in session.GetPeers()) { if (peer.IsReady()) { peer.m_rpc.Invoke("AdminAnimals_PlaySound_v1", new object[1] { val }); } } if (Object.op_Implicit((Object)(object)Player.m_localPlayer)) { AnimalSound.Play(val); } } private void OnPlaySound(ZRpc rpc, ZDOID id) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) if (!session.IsServer() && session.GetServerPeer()?.m_rpc == rpc) { AnimalSound.Play(id); } } } internal sealed class AnimalSpec { internal readonly string Name; internal readonly string Prefab; internal readonly bool Bird; internal AnimalSpec(string name, string prefab, bool bird = false) { Name = name; Prefab = prefab; Bird = bird; } internal GameObject GetPrefab() { if (!Object.op_Implicit((Object)(object)ZNetScene.instance)) { return null; } return ZNetScene.instance.GetPrefab(Prefab); } internal GameObject GetGroundVisual() { GameObject prefab = GetPrefab(); Transform val = (Object.op_Implicit((Object)(object)prefab) ? prefab.transform.Find("Visual") : null); if (!Object.op_Implicit((Object)(object)val) || Object.op_Implicit((Object)(object)((Component)val).GetComponentInChildren<Character>(true)) || Object.op_Implicit((Object)(object)((Component)val).GetComponentInChildren<BaseAI>(true)) || Object.op_Implicit((Object)(object)((Component)val).GetComponentInChildren<ZNetView>(true))) { return null; } return ((Component)val).gameObject; } internal bool Available() { GameObject prefab = GetPrefab(); if (!Object.op_Implicit((Object)(object)prefab)) { return false; } if (Bird) { RandomFlyingBird component = prefab.GetComponent<RandomFlyingBird>(); if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.m_flyingModel)) { if (!component.m_singleModel) { return Object.op_Implicit((Object)(object)component.m_landedModel); } return true; } return false; } GameObject groundVisual = GetGroundVisual(); if (Object.op_Implicit((Object)(object)prefab.GetComponent<Character>()) && Object.op_Implicit((Object)(object)groundVisual) && Object.op_Implicit((Object)(object)groundVisual.GetComponentInChildren<Animator>(true))) { return Object.op_Implicit((Object)(object)groundVisual.GetComponentInChildren<Renderer>(true)); } return false; } } internal static class Animals { internal static readonly AnimalSpec[] All = new AnimalSpec[11] { new AnimalSpec("boar", "Boar"), new AnimalSpec("deer", "Deer"), new AnimalSpec("neck", "Neck"), new AnimalSpec("wolf", "Wolf"), new AnimalSpec("lox", "Lox"), new AnimalSpec("hen", "Hen"), new AnimalSpec("chicken", "Chicken"), new AnimalSpec("hare", "Hare"), new AnimalSpec("asksvin", "Asksvin"), new AnimalSpec("crow", "Crow", bird: true), new AnimalSpec("seagull", "Seagal", bird: true) }; internal static AnimalSpec Find(string name) { if (string.Equals(name, "bird", StringComparison.OrdinalIgnoreCase)) { name = "crow"; } if (string.Equals(name, "rabbit", StringComparison.OrdinalIgnoreCase)) { name = "hare"; } return All.FirstOrDefault((AnimalSpec a) => string.Equals(name, a.Name, StringComparison.OrdinalIgnoreCase)); } } internal static class AnimalSound { internal static void Play(ZDOID id) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) GameObject val = (Object.op_Implicit((Object)(object)ZNetScene.instance) ? ZNetScene.instance.FindInstance(id) : null); Player val2 = (Object.op_Implicit((Object)(object)val) ? val.GetComponent<Player>() : null); FormRecord formRecord = (Object.op_Implicit((Object)(object)val2) ? Plugin.Instance.Network.Get((Character)(object)val2) : null); GameObject val3 = ((formRecord == null) ? null : Animals.Find(formRecord.Animal))?.GetPrefab(); BaseAI val4 = (Object.op_Implicit((Object)(object)val3) ? val3.GetComponent<BaseAI>() : null); if (!Object.op_Implicit((Object)(object)val2) || ((Character)val2).IsDead()) { return; } if (Object.op_Implicit((Object)(object)val4)) { val4.m_idleSound.Create(((Component)val2).transform.position, Quaternion.identity, (Transform)null, 1f, -1, default(ZDOID)); return; } RandomFlyingBird val5 = (Object.op_Implicit((Object)(object)val3) ? val3.GetComponent<RandomFlyingBird>() : null); if (Object.op_Implicit((Object)(object)val5)) { val5.m_randomNoise.Create(((Component)val2).transform.position, Quaternion.identity, (Transform)null, 1f, -1, default(ZDOID)); } } } internal sealed class BirdCompatibility { private readonly List<Tuple<Type, MethodInfo, FieldInfo>> forms = new List<Tuple<Type, MethodInfo, FieldInfo>>(); internal void Install(Harmony harmony) { //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Expected O, but got Unknown //IL_016f: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Expected O, but got Unknown //IL_0191: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Expected O, but got Unknown string[] array = new string[2] { "cheyenne.hearthbird", "cheyenne.hearthsort" }; foreach (string text in array) { if (!Chainloader.PluginInfos.TryGetValue(text, out var value)) { continue; } Assembly assembly = ((object)value.Instance).GetType().Assembly; string text2 = ((text == "cheyenne.hearthbird") ? "HearthBird" : "HearthSort"); Type type = assembly.GetType(text2 + ".BirdNetwork"); if (!(type == null)) { MethodInfo methodInfo = AccessTools.Method(type, "IsBird", (Type[])null, (Type[])null); MethodInfo methodInfo2 = AccessTools.Method(type, "Toggle", (Type[])null, (Type[])null); MethodInfo methodInfo3 = AccessTools.Method(type, "RequestToggle", (Type[])null, (Type[])null); Type type2 = assembly.GetType(text2 + ".BirdForm"); MethodInfo methodInfo4 = AccessTools.Method(type2, "End", (Type[])null, (Type[])null); FieldInfo fieldInfo = ((type2 == null) ? null : AccessTools.Field(type2, "active")); if (methodInfo == null || methodInfo2 == null || methodInfo3 == null || type2 == null || methodInfo4 == null || fieldInfo == null) { throw new InvalidOperationException("Installed bird mod has an unsupported API. Update it before using Admin Animals."); } harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(BirdCompatibility), "IsBird", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)methodInfo2, new HarmonyMethod(typeof(BirdCompatibility), "Toggle", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)methodInfo3, new HarmonyMethod(typeof(BirdCompatibility), "Request", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); forms.Add(Tuple.Create(type2, methodInfo4, fieldInfo)); } } } private static void IsBird(Character player, ref bool __result) { Plugin instance = Plugin.Instance; if (instance != null && instance.Network?.Locked(player) == true) { __result = false; } } private static bool Toggle(long sender, bool enable) { if (enable) { Plugin instance = Plugin.Instance; if (instance == null) { return true; } return instance.Network?.PeerLocked(sender) != true; } return true; } private static bool Request(ref bool __result) { Plugin instance = Plugin.Instance; if (instance == null || instance.Network?.Locked((Character)(object)Player.m_localPlayer) != true) { return true; } Plugin.Instance.Message("Your animal form is held by an admin."); __result = false; return false; } internal void Yield(Player p) { bool flag = default(bool); foreach (Tuple<Type, MethodInfo, FieldInfo> form in forms) { Component component = ((Component)p).GetComponent(form.Item1); if (Object.op_Implicit((Object)(object)component)) { object value = form.Item3.GetValue(component); int num; if (value is bool) { flag = (bool)value; num = 1; } else { num = 0; } if (((uint)num & (flag ? 1u : 0u)) != 0) { object[] parameters = ((form.Item2.GetParameters().Length != 2) ? new object[1] { false } : new object[2] { false, true }); form.Item2.Invoke(component, parameters); } } } } } internal static class Commands { [Serializable] [CompilerGenerated] private sealed class <>c { public static readonly <>c <>9 = new <>c(); public static ConsoleEvent <>9__0_0; public static ConsoleEvent <>9__0_1; public static ConsoleEvent <>9__0_2; internal void <Register>b__0_0(ConsoleEventArgs a) { Run(a, tools: false); } internal void <Register>b__0_1(ConsoleEventArgs a) { Run(a, tools: true); } internal void <Register>b__0_2(ConsoleEventArgs a) { Plugin.Instance.Network.RequestSound(); } } internal static void Register() { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Expected O, but got Unknown //IL_006c: 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_0062: Expected O, but got Unknown //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Expected O, but got Unknown object obj = <>c.<>9__0_0; if (obj == null) { ConsoleEvent val = delegate(ConsoleEventArgs a) { Run(a, tools: false); }; <>c.<>9__0_0 = val; obj = (object)val; } new ConsoleCommand("animalform", "animalform <player> <animal|human> [seconds] | list | status | clearall. Tools disabled.", (ConsoleEvent)obj, false, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); object obj2 = <>c.<>9__0_1; if (obj2 == null) { ConsoleEvent val2 = delegate(ConsoleEventArgs a) { Run(a, tools: true); }; <>c.<>9__0_1 = val2; obj2 = (object)val2; } new ConsoleCommand("animalplay", "animalplay <player> <animal|human> [seconds]. Normal items and tools remain usable.", (ConsoleEvent)obj2, false, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); object obj3 = <>c.<>9__0_2; if (obj3 == null) { ConsoleEvent val3 = delegate { Plugin.Instance.Network.RequestSound(); }; <>c.<>9__0_2 = val3; obj3 = (object)val3; } new ConsoleCommand("animalsound", "Make your current animal's native idle sound.", (ConsoleEvent)obj3, false, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); } private static void Run(ConsoleEventArgs args, bool tools) { try { string[] array = Rules.Tokens(args.FullLine).Skip(1).ToArray(); if (array.Length == 0) { args.Context.AddString("Usage: " + (tools ? "animalplay" : "animalform") + " \"Player Name\" animal [seconds]. Omitted/0 duration means until admin release."); } else { Plugin.Instance.Network.Command(array, tools, args.Context); } } catch (Exception ex) { args.Context.AddString(ex.Message); } } } internal sealed class ForcedBird : MonoBehaviour { private Player player; private Rigidbody body; private CapsuleCollider capsule; private float oldRadius; private float oldHeight; private Vector3 oldCenter; private int oldCapsuleDirection; private Vector3 lastClearPosition; private Vector3 entryPosition; private Vector3 lastClearanceProbe; private float nextClearanceProbe; private Collider[] clearanceHits; private const float BirdRadius = 0.22f; private const float BirdHeight = 0.55f; private const float ClearanceInterval = 0.5f; private GameObject modelRoot; private GameObject flyingModel; private GameObject landedModel; private readonly Dictionary<Renderer, bool> renderers = new Dictionary<Renderer, bool>(); private readonly Dictionary<Light, bool> lights = new Dictionary<Light, bool>(); private bool active; private bool flying; private bool takeoff; private bool landing; private bool sprinting; private bool oldGravity; private CollisionDetectionMode oldCollision; private Vector3 oldEye; private float launchedAt; private float nextRenderScan; private float settlingUntil; private Vector3 direction; private float airspeed; private BirdSprint sprintInput; private BirdJump jumpInput; private Animator[] animators; private AnimatorControllerParameter[][] animatorParameters; private string animal; private bool tools; private float nextFailure; private PlayerController controller; private static readonly Func<PlayerController, bool, bool> TakeInput = AccessTools.MethodDelegate<Func<PlayerController, bool, bool>>(AccessTools.Method(typeof(PlayerController), "TakeInput", (Type[])null, (Type[])null), (object)null, true); private static readonly int LandedKey = StringExtensionMethods.GetStableHashCode("AdminAnimals.bird.landed"); private static readonly FieldRef<Character, float> GroundTouch = AccessTools.FieldRefAccess<Character, float>("m_lastGroundTouch"); private static readonly FieldRef<Character, float> JumpTimer = AccessTools.FieldRefAccess<Character, float>("m_jumpTimer"); private static readonly FieldRef<Character, float> FallTimer = AccessTools.FieldRefAccess<Character, float>("m_fallTimer"); private static readonly FieldRef<Character, float> AirAltitude = AccessTools.FieldRefAccess<Character, float>("m_maxAirAltitude"); private static readonly FieldRef<Player, bool> Crouch = AccessTools.FieldRefAccess<Player, bool>("m_crouchToggled"); internal bool InFlight { get { if (active) { return flying; } return false; } } internal bool IsSprinting => sprinting; internal void PrepareTakeoffInput(bool confirmationHeld) { jumpInput.Arm(confirmationHeld); } internal static bool IsActive(Character c) { Plugin instance = Plugin.Instance; if (instance == null) { return false; } return instance.Network?.IsBird(c) == true; } internal static ForcedBird For(Player p) { ForcedBird component = ((Component)p).GetComponent<ForcedBird>(); if (!Object.op_Implicit((Object)(object)component)) { return ((Component)p).gameObject.AddComponent<ForcedBird>(); } return component; } private RandomFlyingBird Prefab() { if (!Object.op_Implicit((Object)(object)ZNetScene.instance)) { return null; } GameObject val = Animals.Find(Plugin.Instance.Network.Get((Character)(object)player)?.Animal)?.GetPrefab(); RandomFlyingBird val2 = default(RandomFlyingBird); if (!Object.op_Implicit((Object)(object)val) || !val.TryGetComponent<RandomFlyingBird>(ref val2) || !Object.op_Implicit((Object)(object)val2.m_flyingModel) || (!val2.m_singleModel && !Object.op_Implicit((Object)(object)val2.m_landedModel))) { return null; } return val2; } private void Awake() { player = ((Component)this).GetComponent<Player>(); body = ((Component)this).GetComponent<Rigidbody>(); capsule = ((Character)player).GetCollider(); controller = ((Component)this).GetComponent<PlayerController>(); } private GameObject CloneVisual(GameObject source) { GameObject val = Object.Instantiate<GameObject>(source, modelRoot.transform, false); MonoBehaviour[] componentsInChildren = val.GetComponentsInChildren<MonoBehaviour>(true); for (int i = 0; i < componentsInChildren.Length; i++) { Object.DestroyImmediate((Object)(object)componentsInChildren[i]); } Collider[] componentsInChildren2 = val.GetComponentsInChildren<Collider>(true); for (int i = 0; i < componentsInChildren2.Length; i++) { Object.DestroyImmediate((Object)(object)componentsInChildren2[i]); } Rigidbody[] componentsInChildren3 = val.GetComponentsInChildren<Rigidbody>(true); for (int i = 0; i < componentsInChildren3.Length; i++) { Object.DestroyImmediate((Object)(object)componentsInChildren3[i]); } AudioSource[] componentsInChildren4 = val.GetComponentsInChildren<AudioSource>(true); for (int i = 0; i < componentsInChildren4.Length; i++) { Object.DestroyImmediate((Object)(object)componentsInChildren4[i]); } val.SetActive(true); return val; } private bool Begin() { //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Expected O, but got Unknown //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: 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_01d9: Unknown result type (might be due to invalid IL or missing references) //IL_01da: Unknown result type (might be due to invalid IL or missing references) //IL_01db: Unknown result type (might be due to invalid IL or missing references) //IL_01e0: Unknown result type (might be due to invalid IL or missing references) //IL_01e1: Unknown result type (might be due to invalid IL or missing references) //IL_01e2: Unknown result type (might be due to invalid IL or missing references) //IL_01e3: Unknown result type (might be due to invalid IL or missing references) //IL_01e8: Unknown result type (might be due to invalid IL or missing references) //IL_01e9: Unknown result type (might be due to invalid IL or missing references) //IL_024d: Unknown result type (might be due to invalid IL or missing references) //IL_0252: 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_0411: Unknown result type (might be due to invalid IL or missing references) //IL_0416: Unknown result type (might be due to invalid IL or missing references) //IL_0420: Unknown result type (might be due to invalid IL or missing references) //IL_0425: Unknown result type (might be due to invalid IL or missing references) //IL_03b7: Unknown result type (might be due to invalid IL or missing references) RandomFlyingBird val = Prefab(); if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)body) || !Object.op_Implicit((Object)(object)capsule)) { return false; } modelRoot = new GameObject("AdminAnimals Bird Visual"); modelRoot.SetActive(false); modelRoot.transform.SetParent(((Component)player).transform, false); flyingModel = CloneVisual(val.m_flyingModel); landedModel = (val.m_singleModel ? flyingModel : CloneVisual(val.m_landedModel)); animators = modelRoot.GetComponentsInChildren<Animator>(true); animatorParameters = animators.Select((Animator a) => a.parameters).ToArray(); animal = Plugin.Instance.Network.Get((Character)(object)player)?.Animal; tools = Plugin.Instance.Network.Get((Character)(object)player)?.Tools ?? false; if (modelRoot.GetComponentsInChildren<Renderer>(true).Length == 0) { Object.Destroy((Object)(object)modelRoot); modelRoot = null; return false; } oldGravity = body.useGravity; oldCollision = body.collisionDetectionMode; oldEye = ((Character)player).m_eye.localPosition; oldRadius = capsule.radius; oldHeight = capsule.height; oldCenter = capsule.center; oldCapsuleDirection = capsule.direction; lastClearPosition = (entryPosition = (lastClearanceProbe = body.position)); nextClearanceProbe = Time.time + 0.5f; if ((Object)(object)player == (Object)(object)Player.m_localPlayer && clearanceHits == null) { clearanceHits = (Collider[])(object)new Collider[32]; } active = true; flying = !((Character)player).IsOnGround(); direction = ((Component)player).transform.forward; if (!tools) { capsule.direction = 1; capsule.radius = Mathf.Min(oldRadius, 0.22f); capsule.height = Mathf.Min(oldHeight, 0.55f); float num = oldCenter.y - Mathf.Max(oldHeight, oldRadius * 2f) * 0.5f; capsule.center = new Vector3(oldCenter.x, num + Mathf.Max(capsule.height, capsule.radius * 2f) * 0.5f, oldCenter.z); } airspeed = (flying ? 4f : 0f); sprinting = false; sprintInput = default(BirdSprint); if ((Object)(object)player == (Object)(object)Player.m_localPlayer) { body.collisionDetectionMode = (CollisionDetectionMode)2; FormRecord formRecord = Plugin.Instance.Network.Get((Character)(object)player); if (formRecord == null || !formRecord.Tools) { ((Character)player).m_eye.localPosition = new Vector3(oldEye.x, 0.65f, oldEye.z); } Crouch.Invoke(player) = false; player.m_autoRun = false; PlayerController.SetTakeInputDelay(0f); } modelRoot.SetActive(true); nextRenderScan = 0f; HidePlayer(); Puff(((Component)player).transform.position + Vector3.up * 0.5f); return true; } private void HidePlayer() { if (Time.unscaledTime >= nextRenderScan) { nextRenderScan = Time.unscaledTime + 0.5f; Renderer[] componentsInChildren = ((Component)player).GetComponentsInChildren<Renderer>(true); foreach (Renderer val in componentsInChildren) { if (!((Component)val).transform.IsChildOf(modelRoot.transform) && !renderers.ContainsKey(val)) { renderers.Add(val, val.forceRenderingOff); } } Light[] componentsInChildren2 = ((Component)player).GetComponentsInChildren<Light>(true); foreach (Light val2 in componentsInChildren2) { if (!((Component)val2).transform.IsChildOf(modelRoot.transform) && !lights.ContainsKey(val2)) { lights.Add(val2, ((Behaviour)val2).enabled); } } componentsInChildren = renderers.Keys.Where((Renderer r) => !Object.op_Implicit((Object)(object)r)).ToArray(); foreach (Renderer key in componentsInChildren) { renderers.Remove(key); } componentsInChildren2 = lights.Keys.Where((Light l) => !Object.op_Implicit((Object)(object)l)).ToArray(); foreach (Light key2 in componentsInChildren2) { lights.Remove(key2); } } foreach (Renderer key3 in renderers.Keys) { if (Object.op_Implicit((Object)(object)key3)) { key3.forceRenderingOff = true; } } foreach (Light key4 in lights.Keys) { if (Object.op_Implicit((Object)(object)key4)) { ((Behaviour)key4).enabled = false; } } } private void LateUpdate() { //IL_0176: Unknown result type (might be due to invalid IL or missing references) //IL_017b: Unknown result type (might be due to invalid IL or missing references) //IL_0198: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Unknown result type (might be due to invalid IL or missing references) //IL_01ab: Unknown result type (might be due to invalid IL or missing references) //IL_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_01c7: Unknown result type (might be due to invalid IL or missing references) //IL_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_01d8: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_0206: Unknown result type (might be due to invalid IL or missing references) //IL_020c: Invalid comparison between Unknown and I4 if (!Object.op_Implicit((Object)(object)player)) { return; } bool flag = IsActive((Character)(object)player); if (active && (animal != Plugin.Instance.Network.Get((Character)(object)player)?.Animal || tools != (Plugin.Instance.Network.Get((Character)(object)player)?.Tools ?? false)) && !End(effect: false)) { return; } if (flag && !active) { if (Time.unscaledTime < nextFailure) { return; } try { if (!Begin()) { nextFailure = Time.unscaledTime + 2f; return; } } catch (Exception e) { End(effect: false); nextFailure = Time.unscaledTime + 2f; Plugin.Instance.Error("Bird visual failed; admin lock retained", e); return; } } if (!flag) { End(effect: true); return; } HidePlayer(); RememberClearPosition(); bool flag2 = (((Object)(object)player == (Object)(object)Player.m_localPlayer) ? flying : (!((Component)player).GetComponent<ZNetView>().GetZDO().GetBool(LandedKey, true))); if ((Object)(object)flyingModel != (Object)(object)landedModel) { flyingModel.SetActive(flag2); landedModel.SetActive(!flag2); } Vector3 velocity = ((Character)player).GetVelocity(); Quaternion val = Quaternion.LookRotation((flag2 && ((Vector3)(ref velocity)).sqrMagnitude > 0.2f) ? ((Vector3)(ref velocity)).normalized : ((Component)player).transform.forward, Vector3.up); modelRoot.transform.rotation = Quaternion.Slerp(modelRoot.transform.rotation, val, Time.deltaTime * 10f); for (int i = 0; i < animators.Length; i++) { AnimatorControllerParameter[] array = animatorParameters[i]; foreach (AnimatorControllerParameter val2 in array) { if ((int)val2.type == 4) { if (val2.name == "flying") { animators[i].SetBool(val2.nameHash, flag2); } if (val2.name == "flapping") { animators[i].SetBool(val2.nameHash, flag2 && Mathf.Repeat(Time.time, 4f) < 2.8f); } } } } if ((Object)(object)player == (Object)(object)Player.m_localPlayer) { ((Component)player).GetComponent<ZNetView>().GetZDO().Set(LandedKey, !flying); } } internal void Controls(ref Vector3 movedir, bool jump, bool crouch) { //IL_0119: 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) //IL_011e: Unknown result type (might be due to invalid IL or missing references) if (active || (!(Time.unscaledTime < nextFailure) && Begin())) { bool canInput = Object.op_Implicit((Object)(object)controller) && TakeInput(controller, arg2: false) && !InventoryGui.IsVisible() && !StoreGui.IsVisible() && !Minimap.IsOpen() && !Hud.InRadial(); sprinting = sprintInput.Update(ZInput.GetButton("Run") || ZInput.GetButton("JoyRun"), ZInput.ToggleRun, canInput); bool flag = jumpInput.Update(ZInput.GetButton("Jump"), ZInput.GetButton("JoyJump"), jump, canInput); takeoff |= flag && !flying && Plugin.Instance.Energy.CanFly; if (crouch && flying) { landing = true; } if (flag && Plugin.Instance.Energy.CanFly) { landing = false; } movedir = (flying ? Vector3.zero : movedir); } } internal bool Motion(float dt) { //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: 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_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_019b: Unknown result type (might be due to invalid IL or missing references) //IL_01b4: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_01fc: Unknown result type (might be due to invalid IL or missing references) //IL_0201: Unknown result type (might be due to invalid IL or missing references) //IL_0204: Unknown result type (might be due to invalid IL or missing references) //IL_020f: Unknown result type (might be due to invalid IL or missing references) //IL_0239: Unknown result type (might be due to invalid IL or missing references) //IL_0247: Unknown result type (might be due to invalid IL or missing references) //IL_0252: Unknown result type (might be due to invalid IL or missing references) //IL_0257: Unknown result type (might be due to invalid IL or missing references) //IL_0262: Unknown result type (might be due to invalid IL or missing references) //IL_0267: Unknown result type (might be due to invalid IL or missing references) //IL_026c: Unknown result type (might be due to invalid IL or missing references) //IL_0233: Unknown result type (might be due to invalid IL or missing references) //IL_0238: Unknown result type (might be due to invalid IL or missing references) //IL_0277: Unknown result type (might be due to invalid IL or missing references) //IL_027c: Unknown result type (might be due to invalid IL or missing references) //IL_0286: Unknown result type (might be due to invalid IL or missing references) //IL_028b: 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_0294: Unknown result type (might be due to invalid IL or missing references) //IL_0299: Unknown result type (might be due to invalid IL or missing references) //IL_02d4: Unknown result type (might be due to invalid IL or missing references) //IL_02d9: Unknown result type (might be due to invalid IL or missing references) //IL_02e6: Unknown result type (might be due to invalid IL or missing references) //IL_02eb: Unknown result type (might be due to invalid IL or missing references) //IL_02ef: 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_032d: Unknown result type (might be due to invalid IL or missing references) //IL_02af: Unknown result type (might be due to invalid IL or missing references) //IL_02b4: Unknown result type (might be due to invalid IL or missing references) //IL_02be: Unknown result type (might be due to invalid IL or missing references) //IL_02c3: Unknown result type (might be due to invalid IL or missing references) //IL_02c8: Unknown result type (might be due to invalid IL or missing references) //IL_02cc: Unknown result type (might be due to invalid IL or missing references) //IL_02d1: Unknown result type (might be due to invalid IL or missing references) //IL_034d: Unknown result type (might be due to invalid IL or missing references) //IL_040c: Unknown result type (might be due to invalid IL or missing references) //IL_0417: Unknown result type (might be due to invalid IL or missing references) //IL_0427: Unknown result type (might be due to invalid IL or missing references) //IL_0467: Unknown result type (might be due to invalid IL or missing references) //IL_0469: Unknown result type (might be due to invalid IL or missing references) //IL_03bf: Unknown result type (might be due to invalid IL or missing references) if (!active && (Time.unscaledTime < nextFailure || !Begin())) { return true; } AirAltitude.Invoke((Character)(object)player) = ((Component)player).transform.position.y; FallTimer.Invoke((Character)(object)player) = 0f; Vector3 val; if (takeoff) { takeoff = false; flying = true; launchedAt = Time.time; airspeed = 4f; val = ((Component)player).transform.forward + Vector3.up * 0.65f; direction = ((Vector3)(ref val)).normalized; GroundTouch.Invoke((Character)(object)player) = 1f; } if (!flying && Time.time >= settlingUntil && !((Character)player).IsOnGround()) { flying = true; launchedAt = Time.time - 1f; direction = ((Component)player).transform.forward; airspeed = 4f; } if (flying && BirdFlight.CanLand(Time.time - launchedAt, ((Character)player).IsOnGround(), direction.y, landing)) { flying = false; airspeed = 0f; landing = false; body.useGravity = true; body.linearVelocity = new Vector3(0f, Mathf.Min(body.linearVelocity.y, 0f), 0f); } if (!flying) { airspeed = 0f; body.useGravity = true; return true; } if (!Plugin.Instance.Energy.CanFly) { ForceLanding(); } Vector3 lookDir = ((Character)player).GetLookDir(); Vector3 forward = default(Vector3); ((Vector3)(ref forward))..ctor(lookDir.x, 0f, lookDir.z); if (((Vector3)(ref forward)).sqrMagnitude < 0.001f) { forward = ((Component)player).transform.forward; } float num = BirdFlight.Pitch(lookDir.y); Vector3 val2 = ((Vector3)(ref forward)).normalized * Mathf.Cos(num) + Vector3.up * Mathf.Sin(num); if (landing) { val = ((Vector3)(ref forward)).normalized - Vector3.up * 0.45f; val2 = ((Vector3)(ref val)).normalized; } if (Time.time - launchedAt < 0.35f) { val = ((Vector3)(ref forward)).normalized + Vector3.up * 0.65f; val2 = ((Vector3)(ref val)).normalized; } val = Vector3.RotateTowards(direction, val2, 1.7453293f * dt, 1f); direction = ((Vector3)(ref val)).normalized; airspeed = BirdFlight.StepSpeed(airspeed, direction.y, sprinting, dt); float num2 = airspeed * dt; RaycastHit val3 = default(RaycastHit); bool flag = body.SweepTest(direction, ref val3, num2 + 0.04f, (QueryTriggerInteraction)1); if (flag && ((RaycastHit)(ref val3)).normal.y > 0.55f && direction.y < 0f && Time.time - launchedAt > 0.45f) { flying = false; airspeed = 0f; landing = false; settlingUntil = Time.time + 0.25f; body.useGravity = true; body.linearVelocity = Vector3.down; return true; } body.useGravity = false; airspeed = BirdFlight.SweptSpeed(airspeed, dt, flag ? new float?(((RaycastHit)(ref val3)).distance) : ((float?)null)); body.linearVelocity = direction * airspeed; body.angularVelocity = Vector3.zero; Vector3 val4 = default(Vector3); ((Vector3)(ref val4))..ctor(direction.x, 0f, direction.z); if (((Vector3)(ref val4)).sqrMagnitude > 0.001f) { body.MoveRotation(Quaternion.LookRotation(val4)); } GroundTouch.Invoke((Character)(object)player) += dt; JumpTimer.Invoke((Character)(object)player) += dt; return false; } private bool HumanFits(Vector3 position) { //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_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0057: 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_0047: 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_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0131: 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_0091: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_0074: 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) Vector3 lossyScale = ((Component)capsule).transform.lossyScale; Vector3 val = ((oldCapsuleDirection == 0) ? Vector3.right : ((oldCapsuleDirection == 2) ? Vector3.forward : Vector3.up)); float num = Mathf.Abs((oldCapsuleDirection == 0) ? lossyScale.x : ((oldCapsuleDirection == 2) ? lossyScale.z : lossyScale.y)); float num2 = ((oldCapsuleDirection == 0) ? Mathf.Max(Mathf.Abs(lossyScale.y), Mathf.Abs(lossyScale.z)) : ((oldCapsuleDirection == 2) ? Mathf.Max(Mathf.Abs(lossyScale.x), Mathf.Abs(lossyScale.y)) : Mathf.Max(Mathf.Abs(lossyScale.x), Mathf.Abs(lossyScale.z)))); float num3 = oldRadius * num2; float num4 = Mathf.Max(oldHeight * num * 0.5f, num3); Vector3 val2 = position + ((Component)capsule).transform.TransformVector(oldCenter); Vector3 val3 = ((Component)capsule).transform.TransformDirection(val) * (num4 - num3); int num5 = Physics.OverlapCapsuleNonAlloc(val2 - val3, val2 + val3, Mathf.Max(0.01f, num3 - 0.02f), clearanceHits, -1, (QueryTriggerInteraction)1); if (num5 == clearanceHits.Length) { return false; } for (int i = 0; i < num5; i++) { Collider val4 = clearanceHits[i]; if (Object.op_Implicit((Object)(object)val4) && !((Object)(object)val4.attachedRigidbody == (Object)(object)body) && !((Component)val4).transform.IsChildOf(((Component)player).transform) && !Physics.GetIgnoreLayerCollision(((Component)capsule).gameObject.layer, ((Component)val4).gameObject.layer) && !Physics.GetIgnoreCollision((Collider)(object)capsule, val4)) { return false; } } return true; } private void RememberClearPosition() { //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0049: 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_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0056: 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_0068: 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_0077: 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) if ((Object)(object)player != (Object)(object)Player.m_localPlayer || !Object.op_Implicit((Object)(object)body) || Time.time < nextClearanceProbe) { return; } nextClearanceProbe = Time.time + 0.5f; Vector3 position = body.position; Vector3 val = position - lastClearanceProbe; if (!(((Vector3)(ref val)).sqrMagnitude < 0.01f)) { lastClearanceProbe = position; if (HumanFits(position)) { lastClearPosition = position; } } } private bool TryRestorePosition(out Vector3 safe) { //IL_0002: 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_000e: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0085: 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_0061: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_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_0098: 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_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) safe = lastClearPosition; if (HumanFits(safe)) { return true; } safe = entryPosition; if (HumanFits(safe)) { return true; } RaycastHit val2 = default(RaycastHit); for (int i = 0; i < 12; i++) { float num = (float)i * MathF.PI * 0.25f; Vector3 val = (Vector3)((i < 8) ? new Vector3(Mathf.Cos(num) * 0.75f, 0.5f, Mathf.Sin(num) * 0.75f) : (Vector3.up * ((float)(i - 7) * 0.5f))); safe = body.position + val; if (HumanFits(safe) && !body.SweepTest(((Vector3)(ref val)).normalized, ref val2, ((Vector3)(ref val)).magnitude, (QueryTriggerInteraction)1)) { return true; } } return false; } private void RestoreCapsule(bool relocate) { //IL_0119: 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_00b3: 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_00d0: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)capsule)) { if (relocate && Object.op_Implicit((Object)(object)player) && (Object)(object)player == (Object)(object)Player.m_localPlayer && Object.op_Implicit((Object)(object)body) && !((Character)player).IsDead() && !((Character)player).IsTeleporting() && !((Character)player).InCutscene() && !((Character)player).InIntro() && !((Character)player).IsAttached() && !HumanFits(body.position) && TryRestorePosition(out var safe)) { body.position = safe; ((Component)player).transform.position = safe; body.linearVelocity = Vector3.zero; GroundTouch.Invoke((Character)(object)player) = 1f; } capsule.radius = oldRadius; capsule.height = oldHeight; capsule.center = oldCenter; capsule.direction = oldCapsuleDirection; } } internal void ForceLanding() { takeoff = false; if (flying) { landing = true; } } internal bool End(bool effect, bool relocate = true) { //IL_0069: 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_01e0: 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_0229: Unknown result type (might be due to invalid IL or missing references) //IL_022e: Unknown result type (might be due to invalid IL or missing references) //IL_0238: Unknown result type (might be due to invalid IL or missing references) //IL_023d: Unknown result type (might be due to invalid IL or missing references) if (active) { if (relocate && !tools && (Object)(object)player == (Object)(object)Player.m_localPlayer && !((Character)player).IsDead() && !((Character)player).IsTeleporting() && !((Character)player).InCutscene() && !((Character)player).InIntro() && !HumanFits(body.position) && !TryRestorePosition(out var _)) { body.useGravity = true; flying = (takeoff = (landing = false)); return false; } jumpInput = default(BirdJump); RestoreCapsule(relocate); foreach (KeyValuePair<Renderer, bool> renderer in renderers) { if (Object.op_Implicit((Object)(object)renderer.Key)) { renderer.Key.forceRenderingOff = renderer.Value; } } foreach (KeyValuePair<Light, bool> light in lights) { if (Object.op_Implicit((Object)(object)light.Key)) { ((Behaviour)light.Key).enabled = light.Value; } } if (Object.op_Implicit((Object)(object)player) && (Object)(object)player == (Object)(object)Player.m_localPlayer) { if (Object.op_Implicit((Object)(object)body)) { body.useGravity = oldGravity; body.collisionDetectionMode = oldCollision; } ((Character)player).m_eye.localPosition = oldEye; AirAltitude.Invoke((Character)(object)player) = ((Component)player).transform.position.y; FallTimer.Invoke((Character)(object)player) = 0f; } if (effect && Object.op_Implicit((Object)(object)player) && !((Character)player).IsDead()) { Puff(((Component)player).transform.position + Vector3.up * 0.5f); } } active = (flying = (takeoff = (landing = (sprinting = false)))); airspeed = 0f; sprintInput = default(BirdSprint); renderers.Clear(); lights.Clear(); if (Object.op_Implicit((Object)(object)modelRoot)) { modelRoot.SetActive(false); Object.Destroy((Object)(object)modelRoot); } modelRoot = null; return true; } private void OnDestroy() { End(effect: false, relocate: false); } internal static void Puff(Vector3 position) { //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Expected O, but got Unknown //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: 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_0105: 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_0113: Unknown result type (might be due to invalid IL or missing references) //IL_012e: 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_013e: Unknown result type (might be due to invalid IL or missing references) //IL_0143: Unknown result type (might be due to invalid IL or missing references) //IL_015a: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Expected O, but got Unknown //IL_017a: 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_0189: Unknown result type (might be due to invalid IL or missing references) //IL_0190: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_01b6: 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_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_01d1: Unknown result type (might be due to invalid IL or missing references) //IL_01df: Unknown result type (might be due to invalid IL or missing references) GameObject val = (Object.op_Implicit((Object)(object)ZNetScene.instance) ? ZNetScene.instance.GetPrefab("vfx_raven_despawn") : null); ParticleSystemRenderer val2 = (Object.op_Implicit((Object)(object)val) ? val.GetComponentInChildren<ParticleSystemRenderer>(true) : null); if (Object.op_Implicit((Object)(object)val2) && Object.op_Implicit((Object)(object)((Renderer)val2).sharedMaterial)) { GameObject val3 = new GameObject("Bird feather puff"); val3.transform.position = position; ParticleSystem val4 = val3.AddComponent<ParticleSystem>(); val4.Stop(true, (ParticleSystemStopBehavior)0); ((Renderer)((Component)val4).GetComponent<ParticleSystemRenderer>()).sharedMaterial = ((Renderer)val2).sharedMaterial; MainModule main = val4.main; ((MainModule)(ref main)).loop = false; ((MainModule)(ref main)).duration = 0.3f; ((MainModule)(ref main)).startLifetime = MinMaxCurve.op_Implicit(0.55f); ((MainModule)(ref main)).startSpeed = MinMaxCurve.op_Implicit(0.35f); ((MainModule)(ref main)).startSize = MinMaxCurve.op_Implicit(0.06f); ((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(new Color(0.65f, 0.68f, 0.72f, 0.3f)); ((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1; ((MainModule)(ref main)).maxParticles = 12; EmissionModule emission = val4.emission; ((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(0f); ((EmissionModule)(ref emission)).SetBursts((Burst[])(object)new Burst[1] { new Burst(0f, (short)9) }); ShapeModule shape = val4.shape; ((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)0; ((ShapeModule)(ref shape)).radius = 0.3f; ColorOverLifetimeModule colorOverLifetime = val4.colorOverLifetime; ((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true; Gradient val5 = new Gradient(); val5.SetKeys((GradientColorKey[])(object)new GradientColorKey[2] { new GradientColorKey(Color.gray, 0f), new GradientColorKey(Color.gray, 1f) }, (GradientAlphaKey[])(object)new GradientAlphaKey[2] { new GradientAlphaKey(0.3f, 0f), new GradientAlphaKey(0f, 1f) }); ((ColorOverLifetimeModule)(ref colorOverLifetime)).color = MinMaxGradient.op_Implicit(val5); val4.Play(); Object.Destroy((Object)(object)val3, 1.2f); } } } internal sealed class ForcedEnergy { private readonly Dictionary<long, FlightEnergy> characters = new Dictionary<long, FlightEnergy>(); private FlightEnergy current; private long currentId; private Hud hud; private RectTransform root; private RectTransform fill; private Image fillImage; private TextMeshProUGUI label; private int displayedEnergy = -1; internal bool CanFly { get { Bind(Player.m_localPlayer); if (current != null) { return current.Value > 0.0; } return false; } } private void Bind(Player player) { if (!Object.op_Implicit((Object)(object)player)) { return; } long playerID = player.GetPlayerID(); if (playerID == 0L) { current = null; currentId = 0L; } else if (current == null || currentId != playerID) { if (!characters.TryGetValue(playerID, out current)) { characters[playerID] = (current = new FlightEnergy(FlightEnergy.ReadSave(player.m_customData))); } currentId = playerID; } } internal void Save(Player player) { if (!((Object)(object)player != (Object)(object)Player.m_localPlayer)) { Bind(player); if (current != null) { player.m_customData["AdminAnimals.flightEnergy"] = current.Save(); } } } internal void Tick(Player player, float dt) { Bind(player); if (current != null && !((Character)player).IsDead() && !((Character)player).InIntro() && !((Character)player).InCutscene() && !((Character)player).IsTeleporting()) { ForcedBird component = ((Component)player).GetComponent<ForcedBird>(); bool flag = ForcedBird.IsActive((Character)(object)player) && Object.op_Implicit((Object)(object)component) && component.InFlight; current.Step(dt, flag, flag && component.IsSprinting, Plugin.Instance.DrainMultiplier.Value); if (flag && current.Value == 0.0) { component.ForceLanding(); } } } private static RectTransform Rect(string name, Transform parent, Vector2 position, Vector2 size) { //IL_0014: 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_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) RectTransform component = new GameObject(name, new Type[1] { typeof(RectTransform) }).GetComponent<RectTransform>(); ((Transform)component).SetParent(parent, false); Vector2 val = default(Vector2); ((Vector2)(ref val))..ctor(0.5f, 0.5f); component.anchorMax = val; component.anchorMin = val; component.anchoredPosition = position; component.sizeDelta = size; return component; } private static Image Panel(RectTransform rect, Color color, Sprite sprite = null) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) Image val = ((Component)rect).gameObject.AddComponent<Image>(); ((Graphic)val).color = color; ((Graphic)val).raycastTarget = false; if (Object.op_Implicit((Object)(object)sprite)) { val.sprite = sprite; val.type = (Type)1; } return val; } internal void UpdateHud() { //IL_0314: Unknown result type (might be due to invalid IL or missing references) //IL_0323: Unknown result type (might be due to invalid IL or missing references) //IL_0328: Unknown result type (might be due to invalid IL or missing references) //IL_0343: Unknown result type (might be due to invalid IL or missing references) //IL_0103: 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) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Unknown result type (might be due to invalid IL or missing references) //IL_015b: 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_0196: 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_01c7: Unknown result type (might be due to invalid IL or missing references) //IL_01e5: Unknown result type (might be due to invalid IL or missing references) //IL_01f4: Unknown result type (might be due to invalid IL or missing references) //IL_0213: Unknown result type (might be due to invalid IL or missing references) //IL_023b: Unknown result type (might be due to invalid IL or missing references) //IL_03cc: Unknown result type (might be due to invalid IL or missing references) //IL_0269: Unknown result type (might be due to invalid IL or missing references) //IL_0278: 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_0409: Unknown result type (might be due to invalid IL or missing references) //IL_03f3: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; Bind(localPlayer); if ((Object)(object)hud != (Object)(object)Hud.instance || (Object.op_Implicit((Object)(object)root) && (!Object.op_Implicit((Object)(object)hud) || !Object.op_Implicit((Object)(object)hud.m_staminaBar2Root) || (Object)(object)((Transform)root).parent != (Object)(object)((Transform)hud.m_staminaBar2Root).parent))) { DestroyHud(); } if (!Object.op_Implicit((Object)(object)localPlayer) || current == null || !Object.op_Implicit((Object)(object)Hud.instance) || !Object.op_Implicit((Object)(object)Hud.instance.m_staminaBar2Root) || !Object.op_Implicit((Object)(object)Hud.instance.m_staminaText)) { if (Object.op_Implicit((Object)(object)root)) { ((Component)root).gameObject.SetActive(false); } return; } if (!Object.op_Implicit((Object)(object)root)) { hud = Hud.instance; RectTransform staminaBar2Root = hud.m_staminaBar2Root; root = Rect("Admin Animals Flight Energy", ((Transform)staminaBar2Root).parent, Vector2.zero, new Vector2(208f, 24f)); root.anchorMin = staminaBar2Root.anchorMin; root.anchorMax = staminaBar2Root.anchorMax; root.pivot = staminaBar2Root.pivot; ((Transform)root).localScale = ((Transform)staminaBar2Root).localScale; Panel(root, new Color(0.05f, 0.07f, 0.09f, 0.9f)); RectTransform val = Rect("Track", (Transform)(object)root, Vector2.zero, new Vector2(200f, 16f)); Panel(val, new Color(0.13f, 0.2f, 0.24f, 0.95f)); fill = Rect("Energy", (Transform)(object)val, new Vector2(-100f, 0f), new Vector2(200f, 16f)); fill.pivot = new Vector2(0f, 0.5f); Image component = ((Component)hud.m_staminaBar2Fast.m_bar).GetComponent<Image>(); fillImage = Panel(fill, Color.cyan, Object.op_Implicit((Object)(object)component) ? component.sprite : null); label = ((Component)Rect("Label", (Transform)(object)root, Vector2.zero, new Vector2(204f, 24f))).gameObject.AddComponent<TextMeshProUGUI>(); ((TMP_Text)label).font = hud.m_staminaText.font; ((TMP_Text)label).fontSharedMaterial = hud.m_staminaText.fontSharedMaterial; ((TMP_Text)label).fontSize = 16f; ((TMP_Text)label).alignment = (TextAlignmentOptions)514; ((Graphic)label).raycastTarget = false; ((Graphic)label).color = Color.white; } root.anchoredPosition = hud.m_staminaBar2Root.anchoredPosition + new Vector2(0f, 38f); ((Transform)root).localScale = ((Transform)hud.m_staminaBar2Root).localScale; ((Component)root).gameObject.SetActive(ForcedBird.IsActive((Character)(object)localPlayer) && current.Value < 100.0 && !((Character)localPlayer).IsDead() && !((Character)localPlayer).InIntro() && hud.IsVisible() && !Hud.IsUserHidden()); float num = (float)(current.Value / 100.0); fill.sizeDelta = new Vector2(200f * num, 16f); ((Graphic)fillImage).color = ((num <= 0.2f) ? new Color(0.94f, 0.48f, 0.22f) : new Color(0.35f, 0.8f, 0.88f)); int num2 = Mathf.FloorToInt((float)current.Value); if (num2 != displayedEnergy) { displayedEnergy = num2; ((TMP_Text)label).text = num2 + "%"; } } internal void DestroyHud() { if (Object.op_Implicit((Object)(object)root)) { Object.Destroy((Object)(object)((Component)root).gameObject); } root = (fill = null); label = null; fillImage = null; hud = null; displayedEnergy = -1; } } [HarmonyPatch] internal static class Patches { private static bool Restricted(Character c) { Plugin instance = Plugin.Instance; if (instance == null) { return false; } return instance.Network?.Restricted(c) == true; } [HarmonyPatch(typeof(Player), "SetControls")] [HarmonyPrefix] private static void Controls(Player __instance, ref Vector3 movedir, ref bool attack, ref bool attackHold, ref bool secondaryAttack, ref bool secondaryAttackHold, ref bool block, ref bool blockHold, ref bool jump, ref bool crouch, ref bool run, ref bool autoRun, ref bool dodge) { if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer) { return; } if (Restricted((Character)(object)__instance)) { attack = (attackHold = (secondaryAttack = (secondaryAttackHold = (block = (blockHold = false))))); } Plugin instance = Plugin.Instance; if (instance == null || instance.Network?.IsBird((Character)(object)__instance) != true) { return; } ForcedBird forcedBird = ForcedBird.For(__instance); forcedBird.Controls(ref movedir, jump, crouch); jump = false; if (!forcedBird.InFlight) { FormRecord formRecord = Plugin.Instance.Network.Get((Character)(object)__instance); if (formRecord != null && formRecord.Tools) { return; } } crouch = (run = (autoRun = (dodge = false))); } [HarmonyPatch(typeof(Character), "UpdateMotion")] [HarmonyPrefix] private static bool Motion(Character __instance, float dt) { //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Expected O, but got Unknown if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer)) { Plugin instance = Plugin.Instance; if (instance != null && instance.Network?.IsBird(__instance) == true) { return ForcedBird.For((Player)__instance).Motion(dt); } } return true; } [HarmonyPatch(typeof(Character), "CustomFixedUpdate")] [HarmonyPrefix] private static void Prepare(Character __instance) { Player val = (Player)(object)((__instance is Player) ? __instance : null); if (val != null) { Plugin instance = Plugin.Instance; if (instance != null && instance.Network?.Locked((Character)(object)val) == true) { Plugin.Instance.Network.Prepare(val); } } } [HarmonyPatch(typeof(Character), "CustomFixedUpdate")] [HarmonyPostfix] private static void Energy(Character __instance, float dt) { //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Expected O, but got Unknown if ((Object)(object)__instance == (Object)(object)Player.m_localPlayer) { Plugin.Instance?.Energy?.Tick((Player)__instance, dt); } } [HarmonyPatch(typeof(Player), "Save")] [HarmonyPrefix] private static void Save(Player __instance) { Plugin.Instance?.Energy?.Save(__instance); } [HarmonyPatch(typeof(Character), "UpdateGroundContact")] [HarmonyPrefix] private static void Landing(Character __instance, ref float ___m_maxAirAltitude) { //IL_003c: Unknown result type (might be due to invalid IL or missing references) Plugin instance = Plugin.Instance; if (instance != null && instance.Network?.IsBird(__instance) == true) { ___m_maxAirAltitude = ((Component)__instance).transform.position.y; } } [HarmonyPatch(typeof(Humanoid), "StartAttack")] [HarmonyPrefix] private static bool Attack(Humanoid __instance, ref bool __result) { if (!Restricted((Character)(object)__instance)) { return true; } __result = false; return false; } [HarmonyPatch(typeof(Player), "PlayerAttackInput")] [HarmonyPrefix] private static bool AttackInput(Player __instance) { return !Restricted((Character)(object)__instance); } [HarmonyPatch(typeof(Humanoid), "UpdateAttack")] [HarmonyPrefix] private static void CancelAttack(Humanoid __instance, ref Attack ___m_currentAttack) { if (R