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 BIRDUP v0.1.5
BepInEx/plugins/BIRDUP/BIRDUP.dll
Decompiled 2 weeks agousing System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.Globalization; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BIRDUP.Core; using BepInEx; using BepInEx.Bootstrap; using HarmonyLib; using Jotunn.Managers; using Jotunn.Utils; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; using UnityEngine.UI; using Valheim.SettingsGui; using Valheim.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("BIRDUP")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.1.5.0")] [assembly: AssemblyInformationalVersion("0.1.5")] [assembly: AssemblyProduct("BIRDUP")] [assembly: AssemblyTitle("BIRDUP")] [assembly: AssemblyVersion("0.1.5.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 BIRDUP { internal sealed class BirdBindings { internal const string ActionName = "BIRDUPToggle"; internal const string BindingSaveKey = "kbmBinding_BIRDUPToggle"; private BirdToggleInput input; private static readonly Action<ZInput, string, string, bool, bool, bool, float, float> AddButton = AccessTools.MethodDelegate<Action<ZInput, string, string, bool, bool, bool, float, float>>(AccessTools.Method(typeof(ZInput), "AddButton", new Type[7] { typeof(string), typeof(string), typeof(bool), typeof(bool), typeof(bool), typeof(float), typeof(float) }, (Type[])null), (object)null, true); private static readonly Func<Player, bool> TakeInput = AccessTools.MethodDelegate<Func<Player, bool>>(AccessTools.Method(typeof(Player), "TakeInput", (Type[])null, (Type[])null), (object)null, true); internal static void Register(ZInput controls, bool restoreSaved) { if (controls == null || controls.GetButtonDef("BIRDUPToggle") != null) { return; } AddButton(controls, "BIRDUPToggle", string.Empty, arg4: false, arg5: true, arg6: true, 0f, 0f); string text = DataMigration.SelectBindingSaveKey((Func<string, bool>)PlatformPrefs.HasKey); if (text == "kbmBinding_HearthBirdToggle") { PlatformPrefs.SetString("kbmBinding_BIRDUPToggle", PlatformPrefs.GetString(text, "")); text = "kbmBinding_BIRDUPToggle"; } if (restoreSaved && text != null) { ButtonDef buttonDef = controls.GetButtonDef("BIRDUPToggle"); if (buttonDef != null) { buttonDef.Rebind(PlatformPrefs.GetString(text, "")); } } } internal void Update() { Player localPlayer = Player.m_localPlayer; if (!Object.op_Implicit((Object)(object)localPlayer) || ZInput.instance == null) { input.Update(pressed: false, canInput: false); return; } bool canInput = Object.op_Implicit((Object)(object)localPlayer) && Object.op_Implicit((Object)(object)Hud.instance) && !Object.op_Implicit((Object)(object)Settings.instance) && !ZInput.s_IsRebindActive && !Hud.InRadial() && !Hud.IsPieceSelectionVisible() && TakeInput(localPlayer) && Plugin.Instance.Birds.CanUse; if (input.Update(ZInput.GetButton("BIRDUPToggle"), canInput)) { Plugin.Instance.Birds.RequestToggle(); } } internal static void AddSettingsRow(List<KeySetting> keys, int rows, int columns, ref Button bottomLeft, ref Button bottomRight) { //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Expected O, but got Unknown //IL_0183: Unknown result type (might be due to invalid IL or missing references) //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_0193: 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_01aa: Expected O, but got Unknown //IL_01d5: 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_01e2: 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_0200: Unknown result type (might be due to invalid IL or missing references) //IL_0218: Unknown result type (might be due to invalid IL or missing references) //IL_0239: Unknown result type (might be due to invalid IL or missing references) //IL_0244: 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_0263: Unknown result type (might be due to invalid IL or missing references) //IL_0273: Unknown result type (might be due to invalid IL or missing references) //IL_027a: Expected O, but got Unknown //IL_0297: Unknown result type (might be due to invalid IL or missing references) //IL_02a6: Unknown result type (might be due to invalid IL or missing references) //IL_02b9: 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_02c8: 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) if (keys == null || keys.Count == 0 || keys.Any((KeySetting key) => key.m_keyName == "BIRDUPToggle")) { return; } RectTransform template = keys[0].m_keyTransform; GridLayoutGroup val = (Object.op_Implicit((Object)(object)template) ? ((Component)((Transform)template).parent).GetComponent<GridLayoutGroup>() : null); if (!Object.op_Implicit((Object)(object)val) || columns <= 0 || rows <= 0 || keys.Any((KeySetting key) => !Object.op_Implicit((Object)(object)key.m_keyTransform) || (Object)(object)((Transform)key.m_keyTransform).parent != (Object)(object)((Transform)template).parent)) { Plugin.Instance.Error("Native bird binding row unavailable", new InvalidOperationException("Keyboard binding grid changed.")); return; } RectTransform val2 = Object.Instantiate<RectTransform>(template, ((Transform)template).parent); ((Object)val2).name = "BIRDUP Binding"; Button button = ((Component)val2).GetComponentInChildren<Button>(true); TMP_Text val3 = ((IEnumerable<TMP_Text>)((Component)val2).GetComponentsInChildren<TMP_Text>(true)).FirstOrDefault((Func<TMP_Text, bool>)((TMP_Text text) => Object.op_Implicit((Object)(object)button) && !text.transform.IsChildOf(((Component)button).transform))); if (!Object.op_Implicit((Object)(object)button) || !Object.op_Implicit((Object)(object)val3)) { Object.Destroy((Object)(object)((Component)val2).gameObject); Plugin.Instance.Error("Native bird binding row unavailable", new InvalidOperationException("Native key row template changed.")); return; } val3.text = "Bird form — BIRDUP"; button.onClick = new ButtonClickedEvent(); ((Transform)val2).SetSiblingIndex(((Transform)keys[keys.Count - 1].m_keyTransform).GetSiblingIndex() + 1); BirdBindingRow birdBindingRow = ((Component)val2).gameObject.AddComponent<BirdBindingRow>(); birdBindingRow.previousLeft = bottomLeft; birdBindingRow.previousRight = bottomRight; keys.Add(new KeySetting { m_keyName = "BIRDUPToggle", m_keyTransform = val2, m_blockedButtons = Array.Empty<KeyCode>() }); (((Component)val2).GetComponent<LayoutElement>() ?? ((Component)val2).gameObject.AddComponent<LayoutElement>()).ignoreLayout = true; val.constraint = (Constraint)2; val.constraintCount = rows; Vector2 anchorMin = (val2.anchorMax = Vector2.up); val2.anchorMin = anchorMin; val2.pivot = new Vector2(0.5f, 0.5f); val2.sizeDelta = val.cellSize; val2.anchoredPosition = new Vector2((float)((LayoutGroup)val).padding.left + val.cellSize.x * 0.5f, (float)(-((LayoutGroup)val).padding.top) - (float)rows * (val.cellSize.y + val.spacing.y) - val.cellSize.y * 0.5f); RectTransform val4 = (RectTransform)((Component)val).transform; float num = (float)(((LayoutGroup)val).padding.top + ((LayoutGroup)val).padding.bottom) + (float)(rows + 1) * val.cellSize.y + (float)rows * val.spacing.y; Rect rect = val4.rect; val4.SetSizeWithCurrentAnchors((Axis)1, Mathf.Max(((Rect)(ref rect)).height + val.cellSize.y + val.spacing.y, num)); bottomLeft = button; } internal static void FinishSettingsRow(List<KeySetting> keys) { //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) KeySetting val = keys?.FirstOrDefault((Func<KeySetting, bool>)((KeySetting item) => item.m_keyName == "BIRDUPToggle")); BirdBindingRow birdBindingRow = ((val != null) ? ((Component)val.m_keyTransform).GetComponent<BirdBindingRow>() : null); if (Object.op_Implicit((Object)(object)birdBindingRow)) { Button componentInChildren = ((Component)val.m_keyTransform).GetComponentInChildren<Button>(true); Navigation navigation = ((Selectable)componentInChildren).navigation; ((Navigation)(ref navigation)).mode = (Mode)4; ((Navigation)(ref navigation)).selectOnUp = (Selectable)(object)birdBindingRow.previousLeft; ((Navigation)(ref navigation)).selectOnRight = (Selectable)(object)birdBindingRow.previousRight; Selectable selectOnLeft = (((Navigation)(ref navigation)).selectOnDown = null); ((Navigation)(ref navigation)).selectOnLeft = selectOnLeft; ((Selectable)componentInChildren).navigation = navigation; if (Object.op_Implicit((Object)(object)birdBindingRow.previousLeft)) { navigation = ((Selectable)birdBindingRow.previousLeft).navigation; ((Navigation)(ref navigation)).selectOnDown = (Selectable)(object)componentInChildren; ((Selectable)birdBindingRow.previousLeft).navigation = navigation; } } } } internal sealed class BirdBindingRow : MonoBehaviour { internal Button previousLeft; internal Button previousRight; } internal sealed class BirdEnergy { 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["BIRDUP.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()) { BirdForm birdForm = (BirdForm.IsActive((Character)(object)player) ? ((Component)player).GetComponent<BirdForm>() : null); bool flag = Object.op_Implicit((Object)(object)birdForm) && birdForm.InFlight; current.Step(dt, flag, flag && birdForm.IsSprinting); if (flag && current.Value == 0.0) { Plugin.Instance.Birds.StopLocal(); birdForm.End(effect: true); Plugin.Instance.Message("Flight energy depleted."); } } } 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_034a: Unknown result type (might be due to invalid IL or missing references) //IL_0359: Unknown result type (might be due to invalid IL or missing references) //IL_035e: Unknown result type (might be due to invalid IL or missing references) //IL_0363: Unknown result type (might be due to invalid IL or missing references) //IL_036a: Unknown result type (might be due to invalid IL or missing references) //IL_036f: Unknown result type (might be due to invalid IL or missing references) //IL_013b: 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_0161: Unknown result type (might be due to invalid IL or missing references) //IL_0173: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Unknown result type (might be due to invalid IL or missing references) //IL_01bb: Unknown result type (might be due to invalid IL or missing references) //IL_01d2: 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_0203: Unknown result type (might be due to invalid IL or missing references) //IL_0221: Unknown result type (might be due to invalid IL or missing references) //IL_0230: Unknown result type (might be due to invalid IL or missing references) //IL_024f: 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_038e: Unknown result type (might be due to invalid IL or missing references) //IL_0393: Unknown result type (might be due to invalid IL or missing references) //IL_039a: Unknown result type (might be due to invalid IL or missing references) //IL_039f: Unknown result type (might be due to invalid IL or missing references) //IL_037d: Unknown result type (might be due to invalid IL or missing references) //IL_03ad: Unknown result type (might be due to invalid IL or missing references) //IL_02a5: 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_0335: Unknown result type (might be due to invalid IL or missing references) //IL_0406: Unknown result type (might be due to invalid IL or missing references) //IL_040b: Unknown result type (might be due to invalid IL or missing references) //IL_041a: Unknown result type (might be due to invalid IL or missing references) //IL_044e: Unknown result type (might be due to invalid IL or missing references) //IL_0438: Unknown result type (might be due to invalid IL or missing references) //IL_0453: Unknown result type (might be due to invalid IL or missing references) //IL_045b: Unknown result type (might be due to invalid IL or missing references) //IL_0460: Unknown result type (might be due to invalid IL or missing references) //IL_046f: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; Bind(localPlayer); if (Object.op_Implicit((Object)(object)root) && ((Object)(object)hud != (Object)(object)Hud.instance || !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)) { HideHud(); return; } if (!(current.Value < 100.0) || !BirdForm.IsActive((Character)(object)localPlayer) || ((Character)localPlayer).IsDead() || ((Character)localPlayer).InIntro() || !Hud.instance.IsVisible() || Hud.IsUserHidden()) { HideHud(); return; } if (!Object.op_Implicit((Object)(object)root)) { hud = Hud.instance; RectTransform staminaBar2Root = hud.m_staminaBar2Root; root = Rect("BIRDUP 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; } Vector2 val2 = hud.m_staminaBar2Root.anchoredPosition + new Vector2(0f, 38f); if (root.anchoredPosition != val2) { root.anchoredPosition = val2; } Vector3 localScale = ((Transform)hud.m_staminaBar2Root).localScale; if (((Transform)root).localScale != localScale) { ((Transform)root).localScale = localScale; } if (!((Component)root).gameObject.activeSelf) { ((Component)root).gameObject.SetActive(true); } float num = (float)(current.Value / 100.0); Vector2 val3 = default(Vector2); ((Vector2)(ref val3))..ctor(200f * num, 16f); if (fill.sizeDelta != val3) { fill.sizeDelta = val3; } Color val4 = ((num <= 0.2f) ? new Color(0.94f, 0.48f, 0.22f) : new Color(0.35f, 0.8f, 0.88f)); if (((Graphic)fillImage).color != val4) { ((Graphic)fillImage).color = val4; } int num2 = Mathf.FloorToInt((float)current.Value); if (num2 != displayedEnergy) { displayedEnergy = num2; ((TMP_Text)label).text = num2 + "%"; } } private void HideHud() { if (Object.op_Implicit((Object)(object)root) && ((Component)root).gameObject.activeSelf) { ((Component)root).gameObject.SetActive(false); } } 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; } } internal sealed class BirdForm : MonoBehaviour { private struct BirdAnimator { internal Animator Animator; internal int FlyingHash; internal int FlappingHash; internal bool HasFlying; internal bool HasFlapping; } private Player player; private ZNetView networkView; 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 readonly List<Renderer> rendererScan = new List<Renderer>(); private readonly List<Light> lightScan = new List<Light>(); private readonly List<BirdAnimator> animators = new List<BirdAnimator>(); private bool? displayedInAir; private bool? displayedFlapping; private bool? publishedLanded; private float nextVisualAttempt; 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 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("BIRDUP.bird.landed"); internal const string FeatherPrefabName = "vfx_raven_feathers"; private static GameObject featherPrefab; private static bool warnedFeathers; 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.Birds?.IsBird(c) == true; } internal static BirdForm For(Player p) { BirdForm component = ((Component)p).GetComponent<BirdForm>(); if (!Object.op_Implicit((Object)(object)component)) { return ((Component)p).gameObject.AddComponent<BirdForm>(); } return component; } private static RandomFlyingBird Prefab() { if (!Object.op_Implicit((Object)(object)ZNetScene.instance)) { return null; } string[] array = new string[2] { "Crow", "Seagal" }; RandomFlyingBird val = default(RandomFlyingBird); foreach (string text in array) { GameObject prefab = ZNetScene.instance.GetPrefab(text); if (Object.op_Implicit((Object)(object)prefab) && prefab.TryGetComponent<RandomFlyingBird>(ref val) && Object.op_Implicit((Object)(object)val.m_flyingModel) && (val.m_singleModel || Object.op_Implicit((Object)(object)val.m_landedModel))) { return val; } } return null; } internal static bool HasModel() { return (Object)(object)Prefab() != (Object)null; } private void Awake() { player = ((Component)this).GetComponent<Player>(); networkView = ((Component)this).GetComponent<ZNetView>(); 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_0030: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Expected O, but got Unknown //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_01f1: Unknown result type (might be due to invalid IL or missing references) //IL_01f6: Unknown result type (might be due to invalid IL or missing references) //IL_0224: 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_0248: 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_024e: Unknown result type (might be due to invalid IL or missing references) //IL_0250: Unknown result type (might be due to invalid IL or missing references) //IL_0255: 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_0258: Unknown result type (might be due to invalid IL or missing references) //IL_025a: Unknown result type (might be due to invalid IL or missing references) //IL_025f: Unknown result type (might be due to invalid IL or missing references) //IL_0261: Unknown result type (might be due to invalid IL or missing references) //IL_02c5: Unknown result type (might be due to invalid IL or missing references) //IL_02ca: Unknown result type (might be due to invalid IL or missing references) //IL_0380: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Invalid comparison between Unknown and I4 //IL_0455: Unknown result type (might be due to invalid IL or missing references) //IL_045a: Unknown result type (might be due to invalid IL or missing references) //IL_0464: 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_03fb: 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("BIRDUP 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)); if (modelRoot.GetComponentsInChildren<Renderer>(true).Length == 0) { Object.Destroy((Object)(object)modelRoot); modelRoot = null; return false; } animators.Clear(); Animator[] componentsInChildren = modelRoot.GetComponentsInChildren<Animator>(true); foreach (Animator val2 in componentsInChildren) { BirdAnimator item = new BirdAnimator { Animator = val2 }; AnimatorControllerParameter[] parameters = val2.parameters; foreach (AnimatorControllerParameter val3 in parameters) { if ((int)val3.type == 4) { if (val3.name == "flying") { item.HasFlying = true; item.FlyingHash = val3.nameHash; } if (val3.name == "flapping") { item.HasFlapping = true; item.FlappingHash = val3.nameHash; } } } if (item.HasFlying || item.HasFlapping) { animators.Add(item); } } displayedInAir = (displayedFlapping = (publishedLanded = null)); 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; 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; ((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.25f; ((Component)player).GetComponentsInChildren<Renderer>(true, rendererScan); foreach (Renderer item in rendererScan) { if (!((Component)item).transform.IsChildOf(modelRoot.transform) && !renderers.ContainsKey(item)) { renderers.Add(item, item.forceRenderingOff); } } ((Component)player).GetComponentsInChildren<Light>(true, lightScan); foreach (Light item2 in lightScan) { if (!((Component)item2).transform.IsChildOf(modelRoot.transform) && !lights.ContainsKey(item2)) { lights.Add(item2, ((Behaviour)item2).enabled); } } rendererScan.Clear(); lightScan.Clear(); foreach (Renderer key in renderers.Keys) { if (!Object.op_Implicit((Object)(object)key)) { rendererScan.Add(key); } } foreach (Light key2 in lights.Keys) { if (!Object.op_Implicit((Object)(object)key2)) { lightScan.Add(key2); } } foreach (Renderer item3 in rendererScan) { renderers.Remove(item3); } foreach (Light item4 in lightScan) { lights.Remove(item4); } rendererScan.Clear(); lightScan.Clear(); } foreach (Renderer key3 in renderers.Keys) { if (Object.op_Implicit((Object)(object)key3) && !key3.forceRenderingOff) { key3.forceRenderingOff = true; } } foreach (Light key4 in lights.Keys) { if (Object.op_Implicit((Object)(object)key4) && ((Behaviour)key4).enabled) { ((Behaviour)key4).enabled = false; } } } private void LateUpdate() { //IL_01de: 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_0201: 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_0214: Unknown result type (might be due to invalid IL or missing references) //IL_0219: Unknown result type (might be due to invalid IL or missing references) //IL_0231: Unknown result type (might be due to invalid IL or missing references) //IL_0236: Unknown result type (might be due to invalid IL or missing references) //IL_0243: Unknown result type (might be due to invalid IL or missing references) //IL_020a: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)player)) { return; } bool flag = IsActive((Character)(object)player); if (flag && !active) { if (Time.unscaledTime < nextVisualAttempt) { return; } try { if (!Begin()) { nextVisualAttempt = Time.unscaledTime + 0.5f; if ((Object)(object)player == (Object)(object)Player.m_localPlayer) { Plugin.Instance.Birds.StopLocal(); } return; } } catch (Exception e) { End(effect: false); nextVisualAttempt = Time.unscaledTime + 0.5f; Plugin.Instance.Error("Bird visual restored after an error", e); if ((Object)(object)player == (Object)(object)Player.m_localPlayer) { Plugin.Instance.Birds.StopLocal(); } return; } } if (!flag) { if (active && (Object)(object)player == (Object)(object)Player.m_localPlayer && Object.op_Implicit((Object)(object)ZNet.instance)) { Plugin.Instance?.Birds?.StopLocal(); } if (active) { End(effect: true); } nextVisualAttempt = 0f; return; } HidePlayer(); RememberClearPosition(); ZDO val = (Object.op_Implicit((Object)(object)networkView) ? networkView.GetZDO() : null); bool flag2 = (((Object)(object)player == (Object)(object)Player.m_localPlayer) ? flying : (val != null && !val.GetBool(LandedKey, true))); bool flag3 = displayedInAir != flag2; if (flag3 && (Object)(object)flyingModel != (Object)(object)landedModel) { flyingModel.SetActive(flag2); landedModel.SetActive(!flag2); } Vector3 velocity = ((Character)player).GetVelocity(); Quaternion val2 = 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, val2, Time.deltaTime * 10f); bool flag4 = flag2 && Mathf.Repeat(Time.time, 4f) < 2.8f; bool flag5 = displayedFlapping != flag4; if (flag3 || flag5) { foreach (BirdAnimator animator in animators) { if (Object.op_Implicit((Object)(object)animator.Animator)) { if (flag3 && animator.HasFlying) { animator.Animator.SetBool(animator.FlyingHash, flag2); } if ((flag5 || flag3) && animator.HasFlapping) { animator.Animator.SetBool(animator.FlappingHash, flag4); } } } } displayedInAir = flag2; displayedFlapping = flag4; if ((Object)(object)player == (Object)(object)Player.m_localPlayer) { if (val != null && publishedLanded != !flying) { val.Set(LandedKey, !flying); publishedLanded = !flying; } if (((Character)player).IsAttached() || ((Character)player).InIntro() || ((Character)player).IsSwimming() || ((Character)player).IsDebugFlying()) { Plugin.Instance.Birds.StopLocal(); } } } internal void Controls(ref Vector3 movedir, bool jump, bool crouch) { //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0108: 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) if (active || 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) { landing = false; } movedir = (Vector3)(flying ? Vector3.zero : new Vector3(0f, 0f, Mathf.Clamp01(movedir.z))); } } internal bool Motion(float dt) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_018e: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0202: Unknown result type (might be due to invalid IL or missing references) //IL_0207: Unknown result type (might be due to invalid IL or missing references) //IL_020a: Unknown result type (might be due to invalid IL or missing references) //IL_0215: Unknown result type (might be due to invalid IL or missing references) //IL_023f: Unknown result type (might be due to invalid IL or missing references) //IL_024d: Unknown result type (might be due to invalid IL or missing references) //IL_0258: Unknown result type (might be due to invalid IL or missing references) //IL_025d: Unknown result type (might be due to invalid IL or missing references) //IL_0268: Unknown result type (might be due to invalid IL or missing references) //IL_026d: Unknown result type (might be due to invalid IL or missing references) //IL_0272: Unknown result type (might be due to invalid IL or missing references) //IL_0239: Unknown result type (might be due to invalid IL or missing references) //IL_023e: Unknown result type (might be due to invalid IL or missing references) //IL_027d: Unknown result type (might be due to invalid IL or missing references) //IL_0282: Unknown result type (might be due to invalid IL or missing references) //IL_028c: Unknown result type (might be due to invalid IL or missing references) //IL_0291: Unknown result type (might be due to invalid IL or missing references) //IL_0296: Unknown result type (might be due to invalid IL or missing references) //IL_029a: Unknown result type (might be due to invalid IL or missing references) //IL_029f: Unknown result type (might be due to invalid IL or missing references) //IL_02da: Unknown result type (might be due to invalid IL or missing references) //IL_02df: Unknown result type (might be due to invalid IL or missing references) //IL_02ec: Unknown result type (might be due to invalid IL or missing references) //IL_02f1: Unknown result type (might be due to invalid IL or missing references) //IL_02f5: 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) //IL_0333: Unknown result type (might be due to invalid IL or missing references) //IL_02b5: Unknown result type (might be due to invalid IL or missing references) //IL_02ba: 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_02c9: Unknown result type (might be due to invalid IL or missing references) //IL_02ce: Unknown result type (might be due to invalid IL or missing references) //IL_02d2: Unknown result type (might be due to invalid IL or missing references) //IL_02d7: Unknown result type (might be due to invalid IL or missing references) //IL_0353: Unknown result type (might be due to invalid IL or missing references) //IL_0412: Unknown result type (might be due to invalid IL or missing references) //IL_041d: Unknown result type (might be due to invalid IL or missing references) //IL_042d: Unknown result type (might be due to invalid IL or missing references) //IL_046d: Unknown result type (might be due to invalid IL or missing references) //IL_046f: Unknown result type (might be due to invalid IL or missing references) //IL_03c5: Unknown result type (might be due to invalid IL or missing references) if (!active && !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) { Plugin.Instance.Birds.StopLocal(); End(effect: true); return true; } 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 End(bool effect, bool relocate = true) { //IL_011e: 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_0108: Unknown result type (might be due to invalid IL or missing references) //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_0191: 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_01a0: Unknown result type (might be due to invalid IL or missing references) if (active) { 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(); animators.Clear(); rendererScan.Clear(); lightScan.Clear(); displayedInAir = (displayedFlapping = (publishedLanded = null)); nextVisualAttempt = 0f; if (Object.op_Implicit((Object)(object)modelRoot)) { modelRoot.SetActive(false); Object.Destroy((Object)(object)modelRoot); } modelRoot = null; } private void OnDestroy() { End(effect: false, relocate: false); } private static void Puff(Vector3 position) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Invalid comparison between Unknown and I4 //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Expected O, but got Unknown //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_017c: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_01a8: Unknown result type (might be due to invalid IL or missing references) //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_01cd: Unknown result type (might be due to invalid IL or missing references) //IL_01f2: Unknown result type (might be due to invalid IL or missing references) //IL_01f7: Unknown result type (might be due to invalid IL or missing references) //IL_0208: Unknown result type (might be due to invalid IL or missing references) //IL_0219: Unknown result type (might be due to invalid IL or missing references) //IL_0234: 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_0245: Unknown result type (might be due to invalid IL or missing references) //IL_024a: Unknown result type (might be due to invalid IL or missing references) //IL_026a: Unknown result type (might be due to invalid IL or missing references) //IL_026f: Unknown result type (might be due to invalid IL or missing references) //IL_0279: Unknown result type (might be due to invalid IL or missing references) //IL_0280: Expected O, but got Unknown //IL_028a: 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_02a0: Unknown result type (might be due to invalid IL or missing references) //IL_02aa: 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_02c6: Unknown result type (might be due to invalid IL or missing references) //IL_02cb: Unknown result type (might be due to invalid IL or missing references) //IL_02dc: Unknown result type (might be due to invalid IL or missing references) //IL_02e1: Unknown result type (might be due to invalid IL or missing references) //IL_02f2: Unknown result type (might be due to invalid IL or missing references) //IL_02f7: Unknown result type (might be due to invalid IL or missing references) //IL_0305: Unknown result type (might be due to invalid IL or missing references) if ((int)SystemInfo.graphicsDeviceType == 4) { return; } GameObject val = null; try { if (!Object.op_Implicit((Object)(object)featherPrefab)) { featherPrefab = PrefabManager.Instance.GetPrefab("vfx_raven_feathers"); } ParticleSystem val2 = (Object.op_Implicit((Object)(object)featherPrefab) ? featherPrefab.GetComponent<ParticleSystem>() : null); ParticleSystemRenderer val3 = (Object.op_Implicit((Object)(object)val2) ? ((Component)val2).GetComponent<ParticleSystemRenderer>() : null); if (!Object.op_Implicit((Object)(object)val2) || !Object.op_Implicit((Object)(object)val3) || !Object.op_Implicit((Object)(object)((Renderer)val3).sharedMaterial) || !Object.op_Implicit((Object)(object)((Renderer)val3).sharedMaterial.shader) || !((Renderer)val3).sharedMaterial.shader.isSupported) { WarnFeathers(new InvalidOperationException("Native feather prefab or particle material is unavailable.")); return; } val = new GameObject("BIRDUP Feather Puff"); val.SetActive(false); val.transform.position = position; GameObject val4 = Object.Instantiate<GameObject>(featherPrefab, val.transform, false); val4.transform.localPosition = Vector3.zero; val4.transform.localRotation = Quaternion.identity; MonoBehaviour[] componentsInChildren = val4.GetComponentsInChildren<MonoBehaviour>(true); for (int i = 0; i < componentsInChildren.Length; i++) { Object.DestroyImmediate((Object)(object)componentsInChildren[i]); } val4.SetActive(true); ParticleSystem component = val4.GetComponent<ParticleSystem>(); component.Stop(true, (ParticleSystemStopBehavior)0); MainModule main = component.main; ((MainModule)(ref main)).loop = false; ((MainModule)(ref main)).playOnAwake = false; ((MainModule)(ref main)).duration = 0.15f; ((MainModule)(ref main)).startDelay = MinMaxCurve.op_Implicit(0f); ((MainModule)(ref main)).startLifetime = new MinMaxCurve(0.75f, 1.1f); ((MainModule)(ref main)).startSpeed = new MinMaxCurve(0.35f, 0.75f); ((MainModule)(ref main)).startSize = new MinMaxCurve(0.16f, 0.24f); ((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(new Color(0.75f, 0.78f, 0.82f, 0.85f)); ((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1; ((MainModule)(ref main)).maxParticles = 12; ((MainModule)(ref main)).stopAction = (ParticleSystemStopAction)0; EmissionModule emission = component.emission; ((EmissionModule)(ref emission)).enabled = true; ((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(0f); ((EmissionModule)(ref emission)).rateOverDistance = MinMaxCurve.op_Implicit(0f); ((EmissionModule)(ref emission)).SetBursts((Burst[])(object)new Burst[1] { new Burst(0f, (short)9) }); ShapeModule shape = component.shape; ((ShapeModule)(ref shape)).enabled = true; ((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)0; ((ShapeModule)(ref shape)).radius = 0.28f; ColorOverLifetimeModule colorOverLifetime = component.colorOverLifetime; ((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true; Gradient val5 = new Gradient(); val5.SetKeys((GradientColorKey[])(object)new GradientColorKey[2] { new GradientColorKey(Color.white, 0f), new GradientColorKey(Color.white, 1f) }, (GradientAlphaKey[])(object)new GradientAlphaKey[3] { new GradientAlphaKey(1f, 0f), new GradientAlphaKey(1f, 0.25f), new GradientAlphaKey(0f, 1f) }); ((ColorOverLifetimeModule)(ref colorOverLifetime)).color = MinMaxGradient.op_Implicit(val5); val.SetActive(true); component.Play(); Object.Destroy((Object)(object)val, 1.5f); } catch (Exception error) { if (Object.op_Implicit((Object)(object)val)) { Object.Destroy((Object)(object)val); } WarnFeathers(error); } } private static void WarnFeathers(Exception error) { if (!warnedFeathers) { warnedFeathers = true; Plugin.Instance?.Error("Bird feather effect skipped", error); } } } internal sealed class BirdNetwork { private const string QueryRpc = "BIRDUP_BirdQuery"; private const string ToggleRpc = "BIRDUP_BirdToggle"; private const string StateRpc = "BIRDUP_BirdState"; private ZNet session; private readonly HashSet<ZRpc> registeredPeers = new HashSet<ZRpc>(); private readonly Dictionary<long, ZDOID> transformed = new Dictionary<long, ZDOID>(); private readonly Dictionary<long, float> requests = new Dictionary<long, float>(); private readonly Dictionary<long, float> toggleRequests = new Dictionary<long, float>(); private readonly List<long> staleIds = new List<long>(); private readonly HashSet<ZRpc> liveConnections = new HashSet<ZRpc>(); private readonly List<ZRpc> staleConnections = new List<ZRpc>(); private PeriodicWork maintenance; private HashSet<ZDOID> visible = new HashSet<ZDOID>(); private float nextQuery; private float nextPublish; private float receivedAt = float.NegativeInfinity; private bool stopRequested; private float nextStop; private ZDOID localCharacter; private static long Self => ZNet.GetUID(); private static long Server { get { if (!ZNet.instance.IsServer()) { return ZNet.instance.GetServerPeer()?.m_uid ?? 0; } return Self; } } internal bool CanUse => Time.unscaledTime - receivedAt < 8f; internal bool IsBird(Character player) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) if (player is Player && CanUse && visible.Contains(player.GetZDOID()) && !player.IsDead() && !player.IsTeleporting()) { return !player.InCutscene(); } return false; } internal void HideMapBirds(List<PlayerInfo> playerList) { if (CanUse && visible.Count != 0) { HideMapBirds(playerList, visible); } } internal static void HideMapBirds(List<PlayerInfo> playerList, HashSet<ZDOID> birds) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) for (int num = playerList.Count - 1; num >= 0; num--) { if (birds.Contains(playerList[num].m_characterID)) { playerList.RemoveAt(num); } } } internal void Update() { //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Expected O, but got Unknown //IL_0111: 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_0118: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_033e: Unknown result type (might be due to invalid IL or missing references) //IL_0345: Unknown result type (might be due to invalid IL or missing references) //IL_0358: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)ZNet.instance)) { if (session != null) { Reset(); } return; } if ((Object)(object)session != (Object)(object)ZNet.instance) { Reset(); session = ZNet.instance; } foreach (ZNetPeer peer in session.GetPeers()) { if (peer.IsReady() && peer.m_rpc != null && registeredPeers.Add(peer.m_rpc)) { peer.m_rpc.Register("BIRDUP_BirdQuery", new Method(PeerQuery)); peer.m_rpc.Register<bool>("BIRDUP_BirdToggle", (Action<ZRpc, bool>)PeerToggle); peer.m_rpc.Register<ZPackage>("BIRDUP_BirdState", (Action<ZRpc, ZPackage>)PeerState); } } Player localPlayer = Player.m_localPlayer; ZDOID val = (Object.op_Implicit((Object)(object)localPlayer) ? ((Character)localPlayer).GetZDOID() : ZDOID.None); if (localCharacter != val) { localCharacter = val; receivedAt = float.NegativeInfinity; nextQuery = 0f; stopRequested = false; } if (Server != 0L && Time.unscaledTime >= nextQuery) { nextQuery = Time.unscaledTime + 2f; if (session.IsServer()) { Query(Self); } else { ZNetPeer serverPeer = session.GetServerPeer(); if (serverPeer != null) { serverPeer.m_rpc.Invoke("BIRDUP_BirdQuery", Array.Empty<object>()); } } } if (stopRequested && Server != 0L && Time.unscaledTime >= nextStop) { nextStop = Time.unscaledTime + 0.5f; SendToggle(enable: false); } bool flag = false; if (maintenance.TryRun(Time.unscaledTime, 0.5f)) { liveConnections.Clear(); staleConnections.Clear(); foreach (ZNetPeer peer2 in session.GetPeers()) { if (peer2.m_rpc != null) { liveConnections.Add(peer2.m_rpc); } } foreach (ZRpc registeredPeer in registeredPeers) { if (!liveConnections.Contains(registeredPeer)) { staleConnections.Add(registeredPeer); } } foreach (ZRpc staleConnection in staleConnections) { registeredPeers.Remove(staleConnection); } staleConnections.Clear(); if (session.IsServer()) { staleIds.Clear(); foreach (KeyValuePair<long, ZDOID> item in transformed) { if (!ConnectedPlayer(item.Key) || CharacterId(item.Key) != item.Value || ZDOMan.instance.GetZDO(item.Value) == null) { staleIds.Add(item.Key); } } flag = staleIds.Count != 0; foreach (long staleId in staleIds) { transformed.Remove(staleId); } RemoveDisconnected(requests); RemoveDisconnected(toggleRequests); staleIds.Clear(); } } if (session.IsServer() && (flag || Time.unscaledTime >= nextPublish)) { Publish(); } } private void Reset() { //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) session = null; registeredPeers.Clear(); transformed.Clear(); requests.Clear(); toggleRequests.Clear(); visible.Clear(); stopRequested = false; staleIds.Clear(); liveConnections.Clear(); staleConnections.Clear(); maintenance = default(PeriodicWork); receivedAt = float.NegativeInfinity; nextQuery = (nextPublish = 0f); localCharacter = ZDOID.None; } private static ZDOID CharacterId(long sender) { //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 (sender != Self) { return ZNet.instance.GetPeer(sender)?.m_characterID ?? ZDOID.None; } return ZNet.instance.LocalPlayerCharacterID; } private static long AuthenticatedPeer(ZRpc connection) { foreach (ZNetPeer peer in ZNet.instance.GetPeers()) { if (peer.IsReady() && peer.m_rpc == connection) { return peer.m_uid; } } return 0L; } private void PeerQuery(ZRpc connection) { if (ZNet.instance.IsServer()) { long num = AuthenticatedPeer(connection); if (num != 0L && num != Self) { Query(num); } } } private void PeerToggle(ZRpc connection, bool enable) { if (ZNet.instance.IsServer()) { long num = AuthenticatedPeer(connection); if (num != 0L && num != Self) { Toggle(num, enable); } } } private void PeerState(ZRpc connection, ZPackage packet) { if (!ZNet.instance.IsServer() && ZNet.instance.GetServerPeer()?.m_rpc == connection) { Receive(Server, packet); } } private void SendToggle(bool enable) { if (!Object.op_Implicit((Object)(object)session)) { return; } if (session.IsServer()) { Toggle(Self, enable); return; } ZNetPeer serverPeer = session.GetServerPeer(); if (serverPeer != null) { serverPeer.m_rpc.Invoke("BIRDUP_BirdToggle", new object[1] { enable }); } } private static bool ConnectedPlayer(long sender) { if (!Object.op_Implicit((Object)(object)ZNet.instance) || !ZNet.instance.IsServer()) { return false; } if (sender == Self) { return (Object)(object)Player.m_localPlayer != (Object)null; } ZNetPeer peer = ZNet.instance.GetPeer(sender); if (peer == null || !peer.IsReady() || peer.m_socket == null) { return false; } return true; } private bool Throttled(long sender, bool toggle = false) { if (sender != Self && ZNet.instance.GetPeer(sender) == null) { return true; } Dictionary<long, float> dictionary = (toggle ? toggleRequests : requests); if (dictionary.TryGetValue(sender, out var value) && Time.unscaledTime - value < 0.25f) { return true; } dictionary[sender] = Time.unscaledTime; return false; } private void Query(long sender) { if (ZNet.instance.IsServer() && !Throttled(sender)) { SendState(sender); } } private void Toggle(long sender, bool enable) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) if (ZNet.instance.IsServer() && !Throttled(sender, toggle: true)) { ZDOID val = CharacterId(sender); ZDO val2 = ((val != ZDOID.None) ? ZDOMan.instance.GetZDO(val) : null); if (enable && ConnectedPlayer(sender) && val2 != null && val2.GetOwner() == sender && val2.GetPrefab() == StringExtensionMethods.GetStableHashCode("Player")) { transformed[sender] = val; } else { transformed.Remove(sender); } Publish(); } } private void Publish() { nextPublish = Time.unscaledTime + 2f; foreach (ZNetPeer peer in ZNet.instance.GetPeers()) { if (peer.IsReady()) { SendState(peer.m_uid); } } if (Object.op_Implicit((Object)(object)Player.m_localPlayer)) { SendState(Self); } } private void RemoveDisconnected(Dictionary<long, float> times) { staleIds.Clear(); foreach (long key in times.Keys) { if (key != Self && session.GetPeer(key) == null) { staleIds.Add(key); } } foreach (long staleId in staleIds) { times.Remove(staleId); } } private void SendState(long recipient) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) ZPackage val = new ZPackage(); val.Write(transformed.Count); foreach (ZDOID value in transformed.Values) { val.Write(value); } val.SetPos(0); if (recipient == Self) { Receive(Self, val); return; } ZNetPeer peer = ZNet.instance.GetPeer(recipient); if (peer != null) { peer.m_rpc.Invoke("BIRDUP_BirdState", new object[1] { val }); } } private void Receive(long sender, ZPackage packet) { //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) if (sender != Server || Server == 0L) { return; } try { int num = packet.ReadInt(); if (num < 0 || num > 1024) { return; } HashSet<ZDOID> hashSet = new HashSet<ZDOID>(); for (int i = 0; i < num; i++) { hashSet.Add(packet.ReadZDOID()); } if (packet.GetPos() != packet.Size()) { return; } if (stopRequested) { if (!hashSet.Contains(localCharacter)) { stopRequested = false; } else { hashSet.Remove(localCharacter); } } visible = hashSet; receivedAt = Time.unscaledTime; } catch (Exception e) { Plugin.Instance.Error("Bird state packet rejected", e); } } internal bool RequestToggle() { Player localPlayer = Player.m_localPlayer; if (!Object.op_Implicit((Object)(object)localPlayer) || !CanUse || stopRequested || !Object.op_Implicit((Object)(object)session) || Server == 0L) { return false; } bool flag = !IsBird((Character)(object)localPlayer); if (flag && ((Character)localPlayer).IsDebugFlying()) { Plugin.Instance.Message("Turn off debug flight before using bird form."); return false; } if (flag && (((Character)localPlayer).IsDead() || ((Character)localPlayer).InIntro() || ((Character)localPlayer).InCutscene() || ((Character)localPlayer).IsTeleporting() || ((Character)localPlayer).IsAttached() || ((Character)localPlayer).InAttack() || ((Character)localPlayer).IsSwimming())) { Plugin.Instance.Message("Land and finish your current action first."); return false; } if (flag && !BirdForm.HasModel()) { Plugin.Instance.Message("Bird model is unavailable in this game version."); return false; } if (flag) { BirdForm.For(localPlayer).PrepareTakeoffInput(ZInput.GetButton("JoyJump")); } SendToggle(flag); return true; } internal void StopLocal() { //IL_004a: Unknown result type (might be due to invalid IL or missing references) stopRequested = true; nextStop = Time.unscaledTime + 0.5f; if (Object.op_Implicit((Object)(object)session) && Server != 0L) { SendToggle(enable: false); } if (Object.op_Implicit((Object)(object)Player.m_localPlayer)) { visible.Remove(((Character)Player.m_localPlayer).GetZDOID()); } } } [HarmonyPatch] internal static class BirdPatches { private sealed class BirdCaption : IRadialConfig { public string LocalizedName { get { if (!BirdForm.IsActive((Character)(object)Player.m_localPlayer)) { return "Bird form"; } return "Return to Viking"; } } public Sprite Sprite { get { GameObject val = (Object.op_Implicit((Object)(object)ObjectDB.instance) ? ObjectDB.instance.GetItemPrefab("Feathers") : null); if (!Object.op_Implicit((Object)(object)val)) { return null; } ItemDrop component = val.GetComponent<ItemDrop>(); if (component == null) { return null; } return component.m_itemData.GetIcon(); } } public void InitRadialConfig(RadialBase radial) { } } private static RadialBase fastBirdClose; [HarmonyPatch(typeof(ZInput), "ResetKBMButtons")] [HarmonyPostfix] private static void RegisterBinding(ZInput __instance) { BirdBindings.Register(__instance, restoreSaved: false); } [HarmonyPatch(typeof(KeyboardMouseSettings), "SetupKeys")] [HarmonyPrefix] private static void BindingRow(List<KeySetting> ___m_keys, int ___m_keyRows, int ___m_keyCols, ref Button ___m_bottomLeftKeyButton, ref Button ___m_bottomRightKeyButton) { BirdBindings.AddSettingsRow(___m_keys, ___m_keyRows, ___m_keyCols, ref ___m_bottomLeftKeyButton, ref ___m_bottomRightKeyButton); } [HarmonyPatch(typeof(KeyboardMouseSettings), "SetupKeys")] [HarmonyPostfix] private static void BindingNavigation(List<KeySetting> ___m_keys) { BirdBindings.FinishSettingsRow(___m_keys); } [HarmonyPatch(typeof(RadialBase), "ConstructRadial")] [HarmonyPrefix] private static void Menu(RadialBase __instance, List<RadialMenuElement> elements) { if (!(__instance.CurrentConfig is ValheimRadialConfig) || elements == null) { return; } Plugin instance = Plugin.Instance; if (instance == null || instance.Birds?.CanUse != true) { return; } GroupElement val = Object.Instantiate<GroupElement>(RadialData.SO.GroupElement); ((Object)val).name = "BIRDUP Bird Toggle"; val.Init((IRadialConfig)(object)new BirdCaption(), (IRadialConfig)null, __instance); ((RadialMenuElement)val).Interact = delegate { bool flag = !BirdForm.IsActive((Character)(object)Player.m_localPlayer); Plugin instance2 = Plugin.Instance; if (instance2 == null || instance2.Birds?.RequestToggle() != true) { return false; } if (flag) { fastBirdClose = __instance; } return true; }; ((RadialMenuElement)val).CloseOnInteract = () => true; int num = elements.FindLastIndex((RadialMenuElement element) => element is EmptyElement); if (num >= 0) { Object.Destroy((Object)(object)((Component)elements[num]).gameObject); elements[num] = (RadialMenuElement)(object)val; } else { elements.Add((RadialMenuElement)(object)val); } } [HarmonyPatch(typeof(RadialBase), "Close")] [HarmonyPrefix] private static void FastBirdClose(RadialBase __instance, ref bool instant) { if (!((Object)(object)fastBirdClose != (Object)(object)__instance)) { fastBirdClose = null; instant = true; PlayerController.SetTakeInputDelay(0f); } } [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) && BirdForm.IsActive((Character)(object)__instance)) { BirdForm.For(__instance).Controls(ref movedir, jump, crouch); attack = (attackHold = (secondaryAttack = (secondaryAttackHold = (block = (blockHold = (jump = (crouch = (run = (autoRun = (dodge = false)))))))))); } } [HarmonyPatch(typeof(Character), "UpdateMotion")] [HarmonyPrefix] private static bool Motion(Character __instance, float dt) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected O, but got Unknown if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && BirdForm.IsActive(__instance)) { return BirdForm.For((Player)__instance).Motion(dt); } return true; } [HarmonyPatch(typeof(Character), "CustomFixedUpdate")] [HarmonyPrefix] private static void PrepareVisual(Character __instance) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Expected O, but got Unknown if (BirdForm.IsActive(__instance)) { BirdForm.For((Player)__instance); } } [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 SaveEnergy(Player __instance) { Plugin.Instance?.Energy?.Save(__instance); } [HarmonyPatch(typeof(Character), "UpdateGroundContact")] [HarmonyPrefix] private static void SafeBirdLanding(Character __instance, ref float ___m_maxAirAltitude) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) if (BirdForm.IsActive(__instance)) { ___m_maxAirAltitude = ((Component)__instance).transform.position.y; } } [HarmonyPatch(typeof(ZNet), "GetOtherPublicPlayers")] [HarmonyPostfix] private static void MapPlayers(List<PlayerInfo> playerList) { Plugin.Instance?.Birds?.HideMapBirds(playerList); } [HarmonyPatch(typeof(EnemyHud), "TestShow")] [HarmonyPrefix] private static bool Nameplate(Character c, ref bool __result) { if (!BirdForm.IsActive(c)) { return true; } __result = false; return false; } [HarmonyPatch(typeof(Player), "GetHoverName")] [HarmonyPostfix] private static void HoverName(Player __instance, ref string __result) { if (BirdForm.IsActive((Character)(object)__instance)) { __result = ""; } } [HarmonyPatch(typeof(Player), "GetHoverText")] [HarmonyPostfix] private static void HoverText(Player __instance, ref string __result) { if (BirdForm.IsActive((Character)(object)__instance)) { __result = ""; } } [HarmonyPatch(typeof(Player), "PlayerAttackInput")] [HarmonyPrefix] private static bool Attack(Player __instance) { return !BirdForm.IsActive((Character)(object)__instance); } [HarmonyPatch(typeof(Player), "Interact")] [HarmonyPrefix] private static bool Interact(Player __instance) { return !BirdForm.IsActive((Character)(object)__instance); } } [BepInPlugin("cheyenne.birdup", "BIRDUP", "0.1.5")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInIncompatibility("cheyenne.hearthbird")] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] public sealed class Plugin : BaseUnityPlugin { public const string Guid = "cheyenne.birdup"; public const string Version = "0.1.5"; internal static Plugin Instance; internal BirdNetwork Birds; internal BirdEnergy Energy; private BirdBindings bindings; private Harmony patches; private bool stopped; private void Awake() { //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Expected O, but got Unknown Instance = this; Birds = new BirdNetwork(); Energy = new BirdEnergy(); bindings = new BirdBindings(); try { if (Chainloader.PluginInfos.TryGetValue("cheyenne.hearthsort", out var value) && value.Metadata.Version < new Version(0, 1, 15)) { throw new InvalidOperationException("Upgrade HearthSort to 0.1.25 or remove the older combined mod before enabling BIRDUP."); } patches = new Harmony("cheyenne.birdup"); patches.PatchAll(typeof(BirdPatches).Assembly); VerifyPatches(); BirdBindings.Register(ZInput.instance, restoreSaved: true); ((BaseUnityPlugin)this).Logger.LogInfo((object)"BIRDUP 0.1.5 loaded; all 17 bird hooks verified."); } catch (Exception ex) { stopped = true; Harmony obj = patches; if (obj != null) { obj.UnpatchSelf(); } ((BaseUnityPlugin)this).Logger.LogError((object)("BIRDUP disabled before use: " + ex)); } } private static void VerifyPatches() { int num = 0; MethodInfo[] methods = typeof(BirdPatches).GetMethods(BindingFlags.Static | BindingFlags.NonPublic); foreach (MethodInfo patch in methods) { Attribute? customAttribute = Attribute.GetCustomAttribute(patch, typeof(HarmonyPatch)); HarmonyPatch val = (HarmonyPatch)(object)((customAttribute is HarmonyPatch) ? customAttribute : null); if (val != null) { MethodInfo methodInfo = AccessTools.Method(((HarmonyAttribute)val).info.declaringType, ((HarmonyAttribute)val).info.methodName, (Type[])null, (Type[])null); Patches patchInfo = Harmony.GetPatchInfo((MethodBase)methodInfo); ReadOnlyCollection<Patch> readOnlyCollection = ((!Attribute.IsDefined(patch, typeof(HarmonyPrefix))) ? patchInfo?.Postfixes : patchInfo?.Prefixes); if (readOnlyCollection == null || !readOnlyCollection.Any((Patch p) => p.owner == "cheyenne.birdup" && p.PatchMethod == patch)) { throw new InvalidOperationException("Required bird hook did not attach: " + methodInfo); } num++; } } if (num != 17) { throw new InvalidOperationException("Unexpected BIRDUP hook count: " + num); } } private void Update() { if (stopped) { return; } try { Birds.Update(); bindings.Update(); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)ex); } } private void LateUpdate() { if (stopped) { return; } try { Energy.UpdateHud(); } catch (Exception ex) { Energy.DestroyHud(); ((BaseUnityPlugin)this).Logger.LogError((object)ex); } } private void OnDestroy() { Energy?.DestroyHud(); foreach (Character allCharacter in Character.GetAllCharacters()) { if (Object.op_Implicit((Object)(object)allCharacter)) { ((Component)allCharacter).GetComponent<BirdForm>()?.End(effect: false); } } Harmony obj = patches; if (obj != null) { obj.UnpatchSelf(); } Instance = null; } internal void Error(string message, Exception e) { ((BaseUnityPlugin)this).Logger.LogWarning((object)(message + ": " + e.Message)); } internal void Message(string message) { if (Object.op_Implicit((Object)(object)Player.m_localPlayer)) { ((Character)Player.m_localPlayer).Message((MessageType)1, message, 0, (Sprite)null, false); } } } } namespace BIRDUP.Core { public struct BirdSprint { private bool held; private bool sprinting; private bool toggleMode; public bool Update(bool pressed, bool toggle, bool canInput) { if (!canInput) { held = pressed; sprinting = false; toggleMode = toggle; return false; } if (toggleMode != toggle) { sprinting = false; } if (toggle) { if (pressed && !held) { sprinting = !sprinting; } } else { sprinting = pressed; } held = pressed; toggleMode = toggle; return sprinting; } } public struct BirdJump { private bool keyboardHeld; private bool confirmationHeld; public void Arm(bool heldConfirmation) { keyboardHeld = false; confirmationHeld = heldConfirmation; } public bool Update(bool keyboard, bool gamepad, bool nativeEdge, bool canInput) { if (!gamepad) { confirmationHeld = false; } bool result = canInput && ((keyboard && !keyboardHeld) || (nativeEdge && !confirmationHeld)); keyboardHeld = keyboard; return result; } } public static class BirdFlight { public const float NominalSpeed = 12f; public const float TakeoffSpeed = 4f; public const float MaximumSpeed = 22f; public const float SprintMultiplier = 1.5f; public const float PitchSpeedAdjustment = 0.25f; public const float Acceleration = 10f; public const float Deceleration = 4f; public const float TurnDegrees = 100f; public const float Skin = 0.04f; public static float Pitch(float lookY) { return (float)Math.Asin(Math.Max(-0.64f, Math.Min(0.64f, lookY))); } public static bool CanLand(float airborneFor, bool contact, float verticalHeading, bool landing) { if (airborneFor > 0.45f && contact) { if (!landing) { return verticalHeading < 0.12f; } return true; } return false; } private static bool Finite(float value) { if (!float.IsNaN(value)) { return !float.IsInfinity(value); } return false; } private static float BoundedSpeed(float speed) { if (!Finite(speed)) { return 0f; } return Math.Max(0f, Math.Min(22f, speed)); } public static float TargetSpeed(float verticalHeading, bool sprint) { float num = (Finite(verticalHeading) ? Math.Max(-1f, Math.Min(1f, verticalHeading / 0.64f)) : 0f); return BoundedSpeed(12f * (sprint ? 1.5f : 1f) * (1f - 0.25f * num)); } public static float StepSpeed(float current, float verticalHeading, bool sprint, float dt) { current = BoundedSpeed(current); if (!Finite(dt) || dt <= 0f) { return current; } float num = TargetSpeed(verticalHeading, sprint); float num2 = ((num > current) ? 10f : 4f) * dt; if (!(num > current)) { return Math.Max(num, current - num2); } return Math.Min(num, current + num2); } public static float SweptSpeed(float speed, float dt, float? obstacleDistance) { speed = BoundedSpeed(speed); if (dt <= 0f || !Finite(dt)) { return 0f; } if (!obstacleDistance.HasValue) { return speed; } if (float.IsNaN(obstacleDistance.Value)) { return 0f; } return Math.Max(0f, Math.Min(speed, (obstacleDistance.Value - 0.04f) / dt)); } } public struct BirdToggleInput { private bool held; public bool Update(bool pressed, bool canInput) { bool num = pressed && !held; held = pressed; return num && canInput; } } public static class DataMigration { public const string PreviousPluginGuid = "cheyenne.hearthbird"; public const string PreviousEnergyKey = "HearthBird.flightEnergy"; public const string PreviousBindingSaveKey = "kbmBinding_HearthBirdToggle"; public const string ToggleAction = "BIRDUPToggle"; public const string BindingSaveKey = "kbmBinding_BIRDUPToggle"; public static string SelectBindingSaveKey(Func<string, bool> contains) { if (contains("kbmBinding_BIRDUPToggle")) { return "kbmBinding_BIRDUPToggle"; } if (!contains("kbmBinding_HearthBirdToggle")) { return null; } return "kbmBinding_HearthBirdToggle"; } } public sealed class FlightEnergy { public const string SaveKey = "BIRDUP.flightEnergy"; public const string LegacySaveKey = "HearthSort.flightEnergy"; public const double Maximum = 100.0; public const double Drain = 6.666666666666667; public const double Recharge = 1.6666666666666667; public const double SprintDrainMultiplier = 1.15; public double Value { get; private set; } = 100.0; public static string ReadSave(IDictionary<string, string> data) { if (data.TryGetValue("BIRDUP.flightEnergy", out var value)) { return value; } if (data.TryGetValue("HearthBird.flightEnergy", out value)) { return value; } if (!data.TryGetValue("HearthSort.flightEnergy", out value)) { return null; } return value; } public FlightEnergy(string saved = null) { if (double.TryParse(saved, NumberStyles.Float, CultureInfo.InvariantCulture, out var result) && !double.IsNaN(result) && !double.IsInfinity(result)) { Value = Math.Max(0.0, Math.Min(100.0, result)); } } public void Step(double dt, bool flying, bool sprinting) { if (!(dt <= 0.0) && !double.IsNaN(dt) && !double.IsInfinity(dt)) { Value = Math.Max(0.0, Math.Min(100.0, Value + dt * (flying ? (-6.666666666666667 * (sprinting ? 1.15 : 1.0)) : 1.6666666666666667))); if (Value < 1E-05) { Value = 0.0; } if (100.0 - Value < 1E-05) { Value = 100.0; } } } public string Save() { return Value.ToString("R", CultureInfo.InvariantCulture); } } internal struct PeriodicWork { private float next; internal bool TryRun(float now, float interval) { if (now < next) { return false; } next = now + interval; return true; } } }