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 Dragonlands v1.0.0
Dragonlands.dll
Decompiled 21 hours ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; using System.IO.Compression; using System.Linq; using System.Linq.Expressions; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Serialization; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using CreatureManager; using Dragonlands.Dragon; using HarmonyLib; using ItemManager; using JetBrains.Annotations; using LocalizationManager; using M2Core.Assets; using M2Core.Config; using M2Core.Content; using M2Core.Patching; using Microsoft.CodeAnalysis; using ServerSync; using SoftReferenceableAssets; using TMPro; using UnityEngine; using UnityEngine.Animations; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.SceneManagement; using UnityEngine.U2D; using UnityEngine.UI; using YamlDotNet.Core; using YamlDotNet.Core.Events; using YamlDotNet.Core.Tokens; using YamlDotNet.Helpers; using YamlDotNet.Serialization; using YamlDotNet.Serialization.Converters; using YamlDotNet.Serialization.EventEmitters; using YamlDotNet.Serialization.NamingConventions; using YamlDotNet.Serialization.NodeDeserializers; using YamlDotNet.Serialization.NodeTypeResolvers; using YamlDotNet.Serialization.ObjectFactories; using YamlDotNet.Serialization.ObjectGraphTraversalStrategies; using YamlDotNet.Serialization.ObjectGraphVisitors; using YamlDotNet.Serialization.Schemas; using YamlDotNet.Serialization.TypeInspectors; using YamlDotNet.Serialization.TypeResolvers; using YamlDotNet.Serialization.Utilities; using YamlDotNet.Serialization.ValueDeserializers; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: <fc95a550-9cea-4ec1-8bd8-3821032baa3e>IgnoresAccessChecksTo("assembly_guiutils")] [assembly: <fc95a550-9cea-4ec1-8bd8-3821032baa3e>IgnoresAccessChecksTo("assembly_utils")] [assembly: <fc95a550-9cea-4ec1-8bd8-3821032baa3e>IgnoresAccessChecksTo("assembly_valheim")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("Dragonlands")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+3a3630604cdc21980a0ba6f6aed22e8d4acaf53b")] [assembly: AssemblyProduct("Dragonlands")] [assembly: AssemblyTitle("Dragonlands")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace Dragonlands { [BepInPlugin("M2Valheim.Dragonlands", "Dragonlands", "1.0.0")] public class Plugin : BaseUnityPlugin { public const string PluginGuid = "M2Valheim.Dragonlands"; public const string PluginName = "Dragonlands"; public const string PluginVersion = "1.0.0"; internal static ManualLogSource Log; internal static readonly ConfigSync Sync = new ConfigSync("M2Valheim.Dragonlands") { DisplayName = "Dragonlands", CurrentVersion = "1.0.0", MinimumRequiredVersion = ModVersion.SameMinorMinimum("1.0.0"), ModRequired = true, IsLocked = true }; private void Awake() { //IL_0017: Unknown result type (might be due to invalid IL or missing references) Log = ((BaseUnityPlugin)this).Logger; Localizer.Load(); new Harmony("M2Valheim.Dragonlands").PatchAll(); DragonCreature.Register(); } } } namespace Dragonlands.Patches { [HarmonyPatch(typeof(Attack), "GetMeleeAttackDir")] internal static class DragonAttackDirPatch { private static void Postfix(Attack __instance, ref Transform originJoint, ref Vector3 attackDir) { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) Humanoid character = __instance.m_character; if (DragonRideControl.TryGet((Character)(object)character, out var control)) { if (control.TryGetAttackDirection(out var direction)) { attackDir = direction; } if (control.TryGetAttackOrigin(out var origin)) { originJoint = origin; } } } } [HarmonyPatch(typeof(MonsterAI), "DoAttack")] internal static class DragonAirAttackPatch { private static bool Prefix(MonsterAI __instance, Character target, ref bool __result) { if (!DragonRideControl.TryGet(((BaseAI)__instance).m_character, out var control) || !control.BlocksAiAttack(target)) { return true; } __result = false; return false; } } [HarmonyPatch(typeof(Attack), "OnAttackTrigger")] internal static class DragonBreathTriggerPatch { private static bool Prefix(Attack __instance) { Humanoid character = __instance.m_character; if (!DragonRideControl.TryGet((Character)(object)character, out var control)) { return true; } if (__instance.IsDone() || !control.PayBreathHit(__instance)) { return false; } DragonBreathHit.Begin(__instance, control); return true; } private static void Finalizer() { DragonBreathHit.End(); } } [HarmonyPatch(typeof(Attack), "AddHitPoint")] internal static class DragonBreathHitPointPatch { private static bool Prefix(Attack __instance, GameObject go, Collider collider, Vector3 point) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) return !DragonBreathHit.IsActive(__instance) || DragonBreathHit.Accept(go, collider, point); } } [HarmonyPatch(typeof(Character), "FreezeFrame")] internal static class DragonBreathFreezeFramePatch { private static bool Prefix(Character __instance) { if (!DragonBreathHit.IsActiveFor(__instance)) { return true; } DragonBreathHit.OnHit(); return false; } } internal static class DragonBreathHit { private static Attack s_attack; private static DragonRideControl s_ctrl; private static Vector3 s_origin; private static Vector3 s_direction; private static bool s_hasFlameAxis; private static bool s_tamed; private static int s_blockMask; private static readonly RaycastHit[] s_hits = (RaycastHit[])(object)new RaycastHit[16]; private const float FlameConeDeg = 7f; private const float FlameSize = 5.5f; private const float FlameStartScale = 0.12f; private const float FlameReach = 30f; private const float FlameMinRadius = 1f; private const float FlameSpeed = 46f; internal static void Begin(Attack attack, DragonRideControl ctrl) { //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) s_attack = attack; s_ctrl = ctrl; s_hasFlameAxis = ctrl.TryGetAttackOrigin(out var origin) && ctrl.TryGetAttackDirection(out s_direction); s_origin = (s_hasFlameAxis ? origin.position : attack.GetAttackOrigin().position); s_tamed = ((Character)attack.m_character).IsTamed(); } internal static void End() { s_attack = null; s_ctrl = null; } internal static bool IsActive(Attack attack) { return s_attack != null && attack == s_attack; } internal static bool IsActiveFor(Character character) { return s_attack != null && (object)character == s_attack.m_character; } internal static void OnHit() { s_ctrl?.OnBreathHit(); } internal static bool Accept(GameObject go, Collider collider, Vector3 point) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) Character component = go.GetComponent<Character>(); if ((Object)(object)component == (Object)null && s_tamed) { return false; } if (s_hasFlameAxis && !InFlame(collider, point)) { return false; } return Visible(point, go) || ((Object)(object)component != (Object)null && Visible(component.GetCenterPoint(), go)); } private static bool InFlame(Collider collider, Vector3 point) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_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) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: 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_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: 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_0108: 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_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0111: 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) Vector3 val = s_origin; Vector3 val2 = s_direction; float num = Vector3.Dot(point - s_origin, s_direction); if (num > 0f && (Object)(object)s_ctrl != (Object)null && s_ctrl.TryGetPastAttackAxis(num / 46f, out var origin, out var direction)) { val = origin; val2 = direction; } Vector3 val3 = val + val2 * Mathf.Max(0f, Vector3.Dot(point - val, val2)); if ((Object)(object)collider != (Object)null) { MeshCollider val4 = (MeshCollider)(object)((collider is MeshCollider) ? collider : null); if (val4 == null || val4.convex) { point = collider.ClosestPoint(val3); } } float num2 = Vector3.Dot(point - val, val2); if (num2 <= 0f) { return false; } float num3 = num2 * Mathf.Tan(0.12217305f) + 2.75f * Mathf.Lerp(0.12f, 1f, num2 / 30f); Vector3 val5 = point - (val + val2 * num2); return ((Vector3)(ref val5)).magnitude <= Mathf.Max(num3, 1f); } private static bool Visible(Vector3 point, GameObject target) { //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0072: 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 (s_blockMask == 0) { s_blockMask = LayerMask.GetMask(new string[4] { "terrain", "static_solid", "Default", "piece" }); } Vector3 val = point - s_origin; float num = ((Vector3)(ref val)).magnitude - 0.2f; if (num <= 0f) { return true; } int num2 = Physics.RaycastNonAlloc(s_origin, ((Vector3)(ref val)).normalized, s_hits, num, s_blockMask, (QueryTriggerInteraction)1); Transform val2 = (((Object)(object)s_ctrl != (Object)null) ? ((Component)s_ctrl).transform.root : null); for (int i = 0; i < num2; i++) { Collider collider = ((RaycastHit)(ref s_hits[i])).collider; if (!((Object)(object)((Component)collider).transform.root == (Object)(object)val2) && !((Object)(object)Projectile.FindHitObject(collider) == (Object)(object)target)) { return false; } } return true; } } [HarmonyPatch(typeof(GameCamera), "GetCameraPosition")] internal static class DragonCameraDistancePatch { private const float CameraSpeedDistance = 4f; private const float SmoothTime = 1.2f; private static float s_extra; private static float s_extraVelocity; private static void Prefix(GameCamera __instance, float dt, out float __state) { __state = __instance.m_distance; float num = 0f; Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer != (Object)null && ((Character)localPlayer).IsAttached()) { IDoodadController doodadController = localPlayer.GetDoodadController(); DragonRideControl control = DragonRideControl.GetControl((Sadle)(object)((doodadController is Sadle) ? doodadController : null)); if ((Object)(object)control != (Object)null) { num = control.CameraSpeedFactor * 4f; } } s_extra = Mathf.SmoothDamp(s_extra, num, ref s_extraVelocity, 1.2f, float.PositiveInfinity, Mathf.Max(dt, 0.0001f)); if (s_extra < 0.001f) { s_extra = 0f; } __instance.m_distance += s_extra; } private static void Finalizer(GameCamera __instance, float __state) { __instance.m_distance = __state; } } [HarmonyPatch(typeof(Character), "TakeOff")] internal static class DragonTakeOffPatch { private static void Postfix(Character __instance) { if (DragonRideControl.TryGet(__instance, out var control)) { control.OnTakeOff(); } } } [HarmonyPatch(typeof(Character), "Land")] internal static class DragonLandPatch { private static bool Prefix(Character __instance) { if (!DragonRideControl.TryGet(__instance, out var control)) { return true; } control.RequestLanding(); return false; } } [HarmonyPatch(typeof(Character), "UpdateFlying")] internal static class DragonUpdateFlyingPatch { private static bool Prefix(Character __instance, float dt) { if (!DragonRideControl.TryGet(__instance, out var control)) { return true; } if ((Object)(object)__instance.m_nview == (Object)null || !__instance.m_nview.IsOwner()) { return true; } return !control.UpdateFlight(dt); } } [HarmonyPatch(typeof(Character), "UpdateRotation")] internal static class DragonUpdateRotationPatch { private static bool Prefix(Character __instance, float turnSpeed, float dt, ref float __result) { //IL_003c: 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_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) if (!DragonRideControl.TryGet(__instance, out var control)) { return true; } Quaternion val = ((__instance.AlwaysRotateCamera() || __instance.m_moveDir == Vector3.zero) ? __instance.m_lookYaw : Quaternion.LookRotation(__instance.m_moveDir)); __result = control.TurnTowards(((Quaternion)(ref val)).eulerAngles.y, turnSpeed * __instance.GetAttackSpeedFactorRotation(), turnSpeed, dt); return false; } } [HarmonyPatch(typeof(Character), "UpdateGroundTilt")] internal static class DragonGroundTiltPatch { private static bool Prefix(Character __instance, float dt) { if (!__instance.m_flying || !__instance.m_nview.IsOwner() || !DragonRideControl.TryGet(__instance, out var control)) { return true; } return !control.UpdateGroundTilt(dt); } } [HarmonyPatch(typeof(Character), "UpdateSwimming")] internal static class DragonUpdateSwimmingPatch { private static bool Prefix(Character __instance, float dt) { if (!__instance.m_flying || !DragonRideControl.TryGet(__instance, out var control)) { return true; } if ((Object)(object)__instance.m_nview == (Object)null || !__instance.m_nview.IsOwner()) { return true; } return !control.UpdateFlight(dt); } } [HarmonyPatch(typeof(Character), "UpdateMotion")] internal static class DragonUpdateMotionPatch { private static void Prefix(Character __instance) { DragonAnimatorSpeeds.Begin(__instance); } private static void Postfix(Character __instance, float dt) { if (DragonRideControl.TryGet(__instance, out var control)) { control.AfterMotion(dt); } } private static void Finalizer() { DragonAnimatorSpeeds.End(); } } [HarmonyPatch(typeof(ZSyncAnimation), "SetFloat", new Type[] { typeof(int), typeof(float) })] internal static class DragonAnimatorSpeeds { private static ZSyncAnimation s_zanim; private static float s_factor = 1f; private static bool s_riderPose; internal static void Begin(Character character) { if (DragonRideControl.TryGet(character, out var control)) { s_factor = (character.m_flying ? control.FlySpeedFactor : control.SpeedFactor); s_riderPose = false; s_zanim = ((s_factor != 1f) ? character.m_zanim : null); } else if ((Object)(object)character == (Object)(object)Player.m_localPlayer) { IDoodadController doodadController = Player.m_localPlayer.GetDoodadController(); Sadle val = (Sadle)(object)((doodadController is Sadle) ? doodadController : null); if (val != null && DragonRideControl.IsDragonSadle(val)) { s_riderPose = true; s_zanim = character.m_zanim; } } } internal static void End() { s_zanim = null; s_riderPose = false; } private static void Prefix(ZSyncAnimation __instance, int hash, ref float value) { if ((Object)(object)s_zanim == (Object)null || __instance != s_zanim) { return; } if (s_riderPose) { if (hash == Character.s_forwardSpeed || hash == Character.s_sidewaySpeed || hash == Character.s_turnSpeed) { value = 0f; } } else if (hash == Character.s_forwardSpeed) { value /= s_factor; } } } [HarmonyPatch(typeof(Hud), "UpdateShipHud")] internal static class DragonHudWindPatch { private static bool s_shipControlsHidden; private static bool Prefix(Hud __instance, Player player, float dt) { //IL_0129: 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_0154: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_017e: 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_0218: Unknown result type (might be due to invalid IL or missing references) //IL_021d: 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_01c4: Unknown result type (might be due to invalid IL or missing references) //IL_01ca: Unknown result type (might be due to invalid IL or missing references) //IL_01cf: Unknown result type (might be due to invalid IL or missing references) if (!IsDragonFlight(player, out var character)) { if (s_shipControlsHidden) { __instance.m_shipControlsRoot.SetActive(true); s_shipControlsHidden = false; } return true; } if (!__instance.IsVisible()) { return false; } if (!s_shipControlsHidden) { __instance.m_shipHudRoot.SetActive(true); __instance.m_rudderSlow.SetActive(false); __instance.m_rudderForward.SetActive(false); __instance.m_rudderFastForward.SetActive(false); __instance.m_rudderBackward.SetActive(false); __instance.m_rudderLeft.SetActive(false); __instance.m_rudderRight.SetActive(false); __instance.m_fullSail.SetActive(false); __instance.m_halfSail.SetActive(false); __instance.m_rudder.SetActive(false); ((Component)__instance.m_shipRudderIndicator).gameObject.SetActive(false); __instance.m_shipControlsRoot.SetActive(false); s_shipControlsHidden = true; } Transform transform = ((Component)character).transform; Camera mainCamera = Utils.GetMainCamera(); float num = (((Object)(object)mainCamera == (Object)null) ? 0f : (0f - Utils.YawFromDirection(((Component)mainCamera).transform.InverseTransformDirection(transform.forward)))); float num2 = (((Object)(object)EnvMan.instance == (Object)null) ? 0f : (0f - Utils.YawFromDirection(transform.InverseTransformDirection(EnvMan.instance.GetWindDir())))); ((Transform)__instance.m_shipWindIndicatorRoot).localRotation = Quaternion.Euler(0f, 0f, num); ((Transform)__instance.m_shipWindIconRoot).localRotation = Quaternion.Euler(0f, 0f, num2); float num3 = 1f; if ((Object)(object)EnvMan.instance != (Object)null) { float num4 = Vector3.Dot(EnvMan.instance.GetWindDir(), -transform.forward); num3 = Mathf.Lerp(0.7f, 1f, 1f - Utils.Abs(num4)) * (1f - Utils.LerpStep(0.75f, 0.8f, num4)); } ((Graphic)__instance.m_shipWindIcon).color = Color.Lerp(Hud.s_shipWindIconColor, Color.white, num3); return false; } private static bool IsDragonFlight(Player player, out Character character) { character = null; if ((Object)(object)player.GetControlledShip() != (Object)null) { return false; } IDoodadController doodadController = player.GetDoodadController(); Sadle val = (Sadle)(object)((doodadController is Sadle) ? doodadController : null); if ((Object)(object)DragonRideControl.GetControl(val) == (Object)null) { return false; } character = val.m_character; return (Object)(object)character != (Object)null && character.IsFlying(); } } [HarmonyPatch(typeof(Player), "SetControls")] internal static class DragonPlayerSetControlsPatch { private static bool s_attackHeld; private static void Prefix(Player __instance, ref bool attack, ref bool attackHold, ref bool secondaryAttack, ref bool jump, ref bool crouch) { if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer) { return; } IDoodadController doodadController = __instance.GetDoodadController(); Sadle val = (Sadle)(object)((doodadController is Sadle) ? doodadController : null); DragonRideControl control = DragonRideControl.GetControl(val); if ((Object)(object)control == (Object)null) { return; } if (jump) { jump = false; if (!((Object)(object)val.m_character != (Object)null) || val.m_character.IsFlying() || !((Character)__instance).IsEncumbered()) { control.SendJump(); } } if (crouch) { crouch = false; control.SendLand(); } if (attack) { attack = false; control.SendAttack(); } if (s_attackHeld && !attackHold) { control.SendAttackRelease(); } s_attackHeld = attackHold; attackHold = false; if (secondaryAttack) { secondaryAttack = false; } } } [HarmonyPatch(typeof(Sadle), "ApplyControlls")] internal static class DragonSadleApplyControllsPatch { private const float DirectionSmoothing = 4f; private static Vector3 s_smoothedDir; private static bool s_hoverRunHeld; private static Vector3 s_lastSentAimTarget = new Vector3(float.MaxValue, 0f, 0f); private static float s_nextAimSendTime; private const float AimRayDistance = 80f; private static int s_aimRayMask; private static readonly RaycastHit[] s_aimHits = (RaycastHit[])(object)new RaycastHit[16]; private static float MinPitchDeg => -55f; private static float MaxPitchDeg => 45f; private static void SendAim(DragonRideControl ctrl) { //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0075: 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_008c: 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_009c: Unknown result type (might be due to invalid IL or missing references) //IL_009e: 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_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: 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) Transform aimOrigin = ctrl.AimOrigin; Transform val = (((Object)(object)GameCamera.instance != (Object)null) ? ((Component)GameCamera.instance).transform : null); if (!((Object)(object)aimOrigin == (Object)null) && !((Object)(object)val == (Object)null)) { float minDist = Mathf.Max(0f, Vector3.Dot(aimOrigin.position - val.position, val.forward)) + 1f; Vector3 val2 = CrosshairTarget(val.position, val.forward, ((Component)ctrl).transform.root, minDist); if (!(Vector3.Angle(s_lastSentAimTarget - val.position, val2 - val.position) < 0.5f) || !(Time.time < s_nextAimSendTime)) { s_lastSentAimTarget = val2; s_nextAimSendTime = Time.time + 0.25f; ctrl.SendAim(val2); } } } private static Vector3 CrosshairTarget(Vector3 camPos, Vector3 camFwd, Transform dragonRoot, float minDist) { //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0151: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_015d: 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) if (s_aimRayMask == 0) { s_aimRayMask = LayerMask.GetMask(new string[11] { "Default", "static_solid", "Default_small", "piece", "terrain", "vehicle", "character", "character_net", "character_ghost", "character_noenv", "hitbox" }); } int num = Physics.RaycastNonAlloc(camPos, camFwd, s_aimHits, 80f, s_aimRayMask, (QueryTriggerInteraction)1); float num2 = 80f; Transform val = (((Object)(object)Player.m_localPlayer != (Object)null) ? ((Component)Player.m_localPlayer).transform.root : null); for (int i = 0; i < num; i++) { Transform root = ((Component)((RaycastHit)(ref s_aimHits[i])).collider).transform.root; if (!((Object)(object)root == (Object)(object)dragonRoot) && !((Object)(object)root == (Object)(object)val) && !(((RaycastHit)(ref s_aimHits[i])).distance < minDist) && ((RaycastHit)(ref s_aimHits[i])).distance < num2) { num2 = ((RaycastHit)(ref s_aimHits[i])).distance; } } return camPos + camFwd * num2; } private static bool Prefix(Sadle __instance, Vector3 moveDir, Vector3 lookDir, bool run, bool block) { //IL_0047: 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_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_009e: 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_00d7: 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_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_0226: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_023a: 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_01a0: Unknown result type (might be due to invalid IL or missing references) //IL_01a9: Unknown result type (might be due to invalid IL or missing references) //IL_01ae: Unknown result type (might be due to invalid IL or missing references) //IL_01ba: Unknown result type (might be due to invalid IL or missing references) //IL_01bf: Unknown result type (might be due to invalid IL or missing references) //IL_01c4: 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_01cf: 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_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0155: 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_0246: Unknown result type (might be due to invalid IL or missing references) //IL_0298: Unknown result type (might be due to invalid IL or missing references) //IL_02a1: Unknown result type (might be due to invalid IL or missing references) //IL_02a8: Expected I4, but got Unknown //IL_02b9: 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_0208: Unknown result type (might be due to invalid IL or missing references) //IL_020c: Unknown result type (might be due to invalid IL or missing references) //IL_0211: Unknown result type (might be due to invalid IL or missing references) //IL_0215: Unknown result type (might be due to invalid IL or missing references) //IL_021a: Unknown result type (might be due to invalid IL or missing references) //IL_021f: 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_01e4: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Unknown result type (might be due to invalid IL or missing references) //IL_025e: Unknown result type (might be due to invalid IL or missing references) //IL_0270: Unknown result type (might be due to invalid IL or missing references) //IL_026b: Unknown result type (might be due to invalid IL or missing references) DragonRideControl control = DragonRideControl.GetControl(__instance); if ((Object)(object)control == (Object)null) { return true; } SendAim(control); Character character = __instance.m_character; if ((Object)(object)character == (Object)null || !character.IsFlying()) { s_smoothedDir = Vector3.zero; s_hoverRunHeld = false; return true; } if ((Object)(object)Player.m_localPlayer == (Object)null) { return false; } if (((Character)Player.m_localPlayer).IsEncumbered()) { run = false; } if (control.IsControlLocked) { s_smoothedDir = ((Component)character).transform.forward; control.SendJumpHeld(); return false; } if (moveDir.z < -0.5f && run) { s_hoverRunHeld = true; } else if (!run || moveDir.z > 0.5f) { s_hoverRunHeld = false; } else if (s_hoverRunHeld) { run = false; } bool flag = moveDir.z > 0.5f || run || block; Vector3 zero = Vector3.zero; if (flag) { Vector3 val = lookDir; val.y = 0f; if (((Vector3)(ref val)).sqrMagnitude < 0.0001f) { val = ((Component)character).transform.forward; } ((Vector3)(ref val)).Normalize(); float num = Mathf.Clamp(Mathf.Asin(Mathf.Clamp(((Vector3)(ref lookDir)).normalized.y, -1f, 1f)) * 57.29578f, MinPitchDeg, MaxPitchDeg); float num2 = num * ((float)Math.PI / 180f); Vector3 val2 = val * Mathf.Cos(num2) + Vector3.up * Mathf.Sin(num2); Vector3 normalized = ((Vector3)(ref val2)).normalized; if (s_smoothedDir == Vector3.zero) { s_smoothedDir = normalized; } float num3 = 1f - Mathf.Exp(-4f * Time.deltaTime); val2 = Vector3.Slerp(s_smoothedDir, normalized, num3); s_smoothedDir = ((Vector3)(ref val2)).normalized; zero = s_smoothedDir; } Speed val3 = ((moveDir.z < -0.5f) ? ((Speed)0) : (run ? ((Speed)2) : ((moveDir.z > 0.5f) ? ((Speed)1) : ((!block) ? ((Speed)4) : ((Speed)3))))); float skillFactor = ((Character)Player.m_localPlayer).GetSkills().GetSkillFactor((SkillType)110); __instance.m_nview.InvokeRPC("Controls", new object[3] { zero, (int)val3, skillFactor }); if (moveDir.z < -0.5f && run) { control.SendHover(); } return false; } } [HarmonyPatch(typeof(Sadle), "UpdateRiding")] internal static class DragonSadleUpdateRidingPatch { private static bool Prefix(Sadle __instance, float dt, ref bool __result) { //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Invalid comparison between Unknown and I4 //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: 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_00f0: Unknown result type (might be due to invalid IL or missing references) DragonRideControl control = DragonRideControl.GetControl(__instance); if ((Object)(object)control == (Object)null) { return true; } Character character = __instance.m_character; if ((Object)(object)character == (Object)null || !character.IsFlying()) { return true; } if (!((Behaviour)__instance).isActiveAndEnabled || !character.IsTamed() || !__instance.HaveValidUser()) { return true; } if (control.IsControlLocked) { ((BaseAI)__instance.m_monsterAI).StopMoving(); character.SetRun(false); ((BaseAI)__instance.m_monsterAI).ResetRandomMovement(); __result = true; return false; } if (((Vector3)(ref __instance.m_controlDir)).magnitude == 0f) { return true; } control.UpdateFlightStamina(__instance, dt); bool run = (int)__instance.m_speed == 2; Vector3 normalized = ((Vector3)(ref __instance.m_controlDir)).normalized; character.SetLookDir(normalized, 0f); character.SetMoveDir(Vector3.zero); character.SetRun(run); ((BaseAI)__instance.m_monsterAI).ResetRandomMovement(); __result = true; return false; } } [HarmonyPatch(typeof(Sadle), "UpdateStamina")] internal static class DragonSadleUpdateStaminaPatch { private static bool Prefix(Sadle __instance) { if ((Object)(object)DragonRideControl.GetControl(__instance) == (Object)null) { return true; } Character character = __instance.m_character; return (Object)(object)character == (Object)null || !character.IsFlying(); } } [HarmonyPatch(typeof(SpawnSystem), "Awake")] internal static class DragonSpawnDistancePatch { [HarmonyPriority(200)] private static void Postfix(SpawnSystem __instance) { if ((Object)(object)DragonCreature.Prefab == (Object)null) { return; } foreach (SpawnSystemList spawnList in __instance.m_spawnLists) { foreach (SpawnData spawner in spawnList.m_spawners) { if ((Object)(object)spawner.m_prefab == (Object)(object)DragonCreature.Prefab) { spawner.m_spawnDistance = 30f; } } } } } } namespace Dragonlands.Dragon { internal sealed class DragonAim { private static readonly int s_aimTargetKey = StringExtensionMethods.GetStableHashCode("M2Dragon_AimTarget"); private const float AimTargetWriteThreshold = 0.05f; private const float AimWriteInterval = 0.1f; private const float NoAimTargetDistance = 30f; private static readonly int s_coldBreathHash = Animator.StringToHash("cold breath"); private static readonly int s_breathAirHash = Animator.StringToHash("breath_air"); private static readonly int s_eatHash = Animator.StringToHash("Eat"); private readonly Transform _transform; private readonly MonsterAI _ai; private readonly ZNetView _nview; private readonly Animator _animator; private readonly DragonHeadAim _headAim; private Vector3 _riderAimTarget; private bool _hasRiderAim; private Vector3 _aimToWrite; private bool _aimWritePending; private float _nextAimWriteTime; private Transform _aimOrigin; private Transform _attackOrigin; internal Transform AimOrigin { get { if ((Object)(object)_aimOrigin == (Object)null) { _aimOrigin = Utils.FindChild(_transform, "MouthSocket", (IterativeSearchType)0); } return _aimOrigin; } } internal DragonAim(Transform transform, MonsterAI ai, ZNetView nview, Animator animator, DragonHeadAim headAim) { _transform = transform; _ai = ai; _nview = nview; _animator = animator; _headAim = headAim; } internal bool TryGetAttackDirection(out Vector3 direction) { //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_0047: 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) direction = Vector3.zero; if ((Object)(object)_headAim == (Object)null || !_headAim.AimActive || !_headAim.HasAimDirection) { return false; } direction = _headAim.AimDirection; return true; } internal bool TryGetAttackOrigin(out Transform origin) { //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) origin = null; if (!TryGetAttackDirection(out var direction)) { return false; } if ((Object)(object)_attackOrigin == (Object)null) { _attackOrigin = new GameObject("M2Dragon_AttackOrigin").transform; _attackOrigin.SetParent(_transform, false); } _attackOrigin.SetPositionAndRotation(_headAim.AimOrigin, Quaternion.LookRotation(direction)); origin = _attackOrigin; return true; } internal bool TryGetPastAttackAxis(float age, out Vector3 origin, out Vector3 direction) { //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_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) origin = Vector3.zero; direction = Vector3.zero; return (Object)(object)_headAim != (Object)null && _headAim.AimActive && _headAim.TryGetAimAxisAt(Time.time - age, out origin, out direction); } internal void SetRiderTarget(Vector3 target) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0003: 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) _riderAimTarget = target; _hasRiderAim = true; QueueAimWrite(target); } internal void UpdateHeadAimTarget(bool ridden) { //IL_009f: 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_015f: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_0152: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: 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_0169: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) //IL_016b: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: 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_0138: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) if (!ridden) { _hasRiderAim = false; } if ((Object)(object)_headAim == (Object)null) { return; } ZDO val = (((Object)(object)_nview != (Object)null && _nview.IsValid()) ? _nview.GetZDO() : null); if (val == null) { _headAim.AimActive = false; return; } bool flag = _nview.IsOwner(); bool flag2; Vector3 val2; if (ridden) { flag2 = !IsEating(); val2 = ((flag && _hasRiderAim) ? _riderAimTarget : val.GetVec3(s_aimTargetKey, Vector3.zero)); if (val2 == Vector3.zero) { val2 = _transform.position + _transform.forward * 30f; } } else if (flag) { Character val3 = ((IsBreathing() && (Object)(object)_ai != (Object)null) ? ((BaseAI)_ai).GetTargetCreature() : null); flag2 = (Object)(object)val3 != (Object)null; val2 = (flag2 ? BodyAxisPoint(val3.GetCenterPoint()) : Vector3.zero); QueueAimWrite(val2); } else { val2 = (IsBreathing() ? val.GetVec3(s_aimTargetKey, Vector3.zero) : Vector3.zero); flag2 = val2 != Vector3.zero; } _headAim.AimActive = flag2; if (flag2) { _headAim.AimTarget = val2; } if (flag) { FlushAimWrite(); } } private bool IsBreathing() { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_animator == (Object)null) { return false; } AnimatorStateInfo currentAnimatorStateInfo = _animator.GetCurrentAnimatorStateInfo(0); int shortNameHash = ((AnimatorStateInfo)(ref currentAnimatorStateInfo)).shortNameHash; return shortNameHash == s_coldBreathHash || shortNameHash == s_breathAirHash; } private Vector3 BodyAxisPoint(Vector3 targetPoint) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0019: 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_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0043: 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_004e: 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_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0075: 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) Vector3 val = targetPoint - _transform.position; Vector3 val2 = Vector3.ProjectOnPlane(_transform.forward, Vector3.up); Vector3 normalized = ((Vector3)(ref val2)).normalized; Vector3 position = _transform.position; Vector2 val3 = new Vector2(val.x, val.z); return position + normalized * ((Vector2)(ref val3)).magnitude + Vector3.up * val.y; } private bool IsEating() { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_animator == (Object)null) { return false; } AnimatorStateInfo val = _animator.GetCurrentAnimatorStateInfo(0); int result; if (((AnimatorStateInfo)(ref val)).shortNameHash != s_eatHash) { if (_animator.IsInTransition(0)) { val = _animator.GetNextAnimatorStateInfo(0); result = ((((AnimatorStateInfo)(ref val)).shortNameHash == s_eatHash) ? 1 : 0); } else { result = 0; } } else { result = 1; } return (byte)result != 0; } private void QueueAimWrite(Vector3 target) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Unknown result type (might be due to invalid IL or missing references) _aimToWrite = target; _aimWritePending = true; FlushAimWrite(); } private void FlushAimWrite() { //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_0069: 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) if (!_aimWritePending || Time.time < _nextAimWriteTime || (Object)(object)_nview == (Object)null || !_nview.IsOwner()) { return; } ZDO zDO = _nview.GetZDO(); if (zDO != null) { _aimWritePending = false; if (!(Vector3.Distance(zDO.GetVec3(s_aimTargetKey, Vector3.zero), _aimToWrite) <= 0.05f)) { zDO.Set(s_aimTargetKey, _aimToWrite); _nextAimWriteTime = Time.time + 0.1f; } } } } internal class DragonAnimEvents : MonoBehaviour { private const float MinWingFlapWeight = 0.3f; private const float WingFlapSpacing = 0.5f; [SerializeField] private GameObject wingFlapSfx; [SerializeField] private Transform wingFlapAnchor; private const float MinVoiceWeight = 0.3f; private const float VoiceSpacing = 1.5f; [SerializeField] private Transform mouthAnchor; private int _fireStates; private DragonRideControl _control; private AnimationEffect _animationEffect; private float _lastWingFlap = -1f; private float _lastVoice = -1f; internal bool InFireState { get; private set; } private void Awake() { _control = ((Component)this).GetComponentInParent<DragonRideControl>(); _animationEffect = ((Component)this).GetComponent<AnimationEffect>(); } public void TakeoffDone() { if ((Object)(object)_control != (Object)null) { _control.OnTakeoffDone(); } } public void Touchdown() { if ((Object)(object)_control != (Object)null) { _control.OnTouchdown(); } } public void WingFlap(AnimationEvent e) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)wingFlapSfx == (Object)null)) { AnimatorClipInfo animatorClipInfo = e.animatorClipInfo; if (!(((AnimatorClipInfo)(ref animatorClipInfo)).weight < 0.3f) && !(Time.time - _lastWingFlap < 0.5f)) { _lastWingFlap = Time.time; Transform val = (((Object)(object)wingFlapAnchor != (Object)null) ? wingFlapAnchor : ((Component)this).transform); Object.Instantiate<GameObject>(wingFlapSfx, val.position, val.rotation); } } } public void Roar(AnimationEvent e) { Voice(DragonCreature.RoarSfx, e, 1f); } public void Growl(AnimationEvent e) { Voice(DragonCreature.GrowlSfx, e, (e.floatParameter > 0f) ? e.floatParameter : 1f); } private void Voice(GameObject sfx, AnimationEvent e, float chance) { //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_0073: 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 (!((Object)(object)sfx == (Object)null)) { AnimatorClipInfo animatorClipInfo = e.animatorClipInfo; if (!(((AnimatorClipInfo)(ref animatorClipInfo)).weight < 0.3f) && !(Time.time - _lastVoice < 1.5f) && !(Random.value > chance)) { _lastVoice = Time.time; Transform val = (((Object)(object)mouthAnchor != (Object)null) ? mouthAnchor : ((Component)this).transform); Object.Instantiate<GameObject>(sfx, val.position, val.rotation); } } } public void RemoveAttachments() { DragonBreathFireVfx.ExtinguishFor(((Component)this).transform, clear: false); } internal void EnterFireState() { _fireStates++; DragonBreathFireVfx.ExtinguishFor(((Component)this).transform, clear: false); InFireState = true; } internal void ExitFireState(bool clear) { if (_fireStates > 0) { _fireStates--; } if (_fireStates == 0) { CloseFireWindow(clear); } } internal void CloseFireWindow(bool clear) { if (InFireState) { InFireState = false; DragonBreathFireVfx.ExtinguishFor(((Component)this).transform, clear); if ((Object)(object)_animationEffect != (Object)null) { _animationEffect.RemoveAttachments(); } } } } [DefaultExecutionOrder(10002)] internal class DragonBreathFireVfx : MonoBehaviour { [SerializeField] private float lightFadeSeconds = 1f; [SerializeField] private ParticleSystem flames; [SerializeField] private Transform groundFire; [SerializeField] private LayerMask groundMask; [SerializeField] private float groundRange = 32f; [SerializeField] private float slideSpeedFactor = 0.7f; [SerializeField] private float impactSmoothTime = 0.1f; [SerializeField] private float impactMaxSpeed = 40f; [SerializeField] private float impactLoseDelay = 0.2f; private static readonly List<DragonBreathFireVfx> s_active = new List<DragonBreathFireVfx>(); private ParticleSystem[] _systems; private ParticleSystem[] _groundSystems; private Light[] _lights; private float[] _lightStart; private LightFlicker[] _flickers; private Light _groundLight; private ParticleSystemRenderer _flamesRenderer; private Particle[] _buffer; private Transform _socket; private Transform _owner; private bool _following; private bool _hasGround; private Vector3 _groundPoint; private Vector3 _groundNormal; private Vector3 _impactVel; private float _missTime; private bool _fading; private float _lightFadeTimer; public static void ExtinguishFor(Transform owner, bool clear) { for (int num = s_active.Count - 1; num >= 0; num--) { DragonBreathFireVfx dragonBreathFireVfx = s_active[num]; if ((Object)(object)dragonBreathFireVfx != (Object)null && (Object)(object)dragonBreathFireVfx._owner == (Object)(object)owner) { dragonBreathFireVfx.Extinguish(clear); } } } private void OnTransformParentChanged() { if (!((Object)(object)_socket != (Object)null) && !_fading && !((Object)(object)((Component)this).transform.parent == (Object)null)) { _socket = ((Component)this).transform.parent; _following = true; Animator componentInParent = ((Component)this).GetComponentInParent<Animator>(); _owner = (((Object)(object)componentInParent != (Object)null) ? ((Component)componentInParent).transform : null); if (!s_active.Contains(this)) { s_active.Add(this); } } } private void Start() { FindParts(); } private void OnDestroy() { s_active.Remove(this); } private void FindParts() { if (_systems == null) { _systems = ((Component)this).GetComponentsInChildren<ParticleSystem>(); _groundSystems = (ParticleSystem[])(((Object)(object)groundFire != (Object)null) ? ((Array)((Component)groundFire).GetComponentsInChildren<ParticleSystem>()) : ((Array)new ParticleSystem[0])); _lights = ((Component)this).GetComponentsInChildren<Light>(); _lightStart = new float[_lights.Length]; _flickers = ((Component)this).GetComponentsInChildren<LightFlicker>(); _groundLight = (((Object)(object)groundFire != (Object)null) ? ((Component)groundFire).GetComponentInChildren<Light>() : null); if ((Object)(object)_groundLight != (Object)null) { ((Behaviour)_groundLight).enabled = false; } if ((Object)(object)flames != (Object)null) { _flamesRenderer = ((Component)flames).GetComponent<ParticleSystemRenderer>(); } } } public void Extinguish(bool clear) { if (_fading) { return; } _fading = true; FindParts(); ((Component)this).transform.SetParent((Transform)null, true); for (int i = 0; i < _systems.Length; i++) { if ((Object)(object)_systems[i] != (Object)null) { _systems[i].Stop(true, (ParticleSystemStopBehavior)(!clear)); } } for (int j = 0; j < _flickers.Length; j++) { if ((Object)(object)_flickers[j] != (Object)null) { ((Behaviour)_flickers[j]).enabled = false; } } for (int k = 0; k < _lights.Length; k++) { if ((Object)(object)_lights[k] != (Object)null) { _lightStart[k] = (((Behaviour)_lights[k]).enabled ? _lights[k].intensity : 0f); } } } private void LateUpdate() { //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) if (!_fading && _following) { if ((Object)(object)_socket == (Object)null) { Extinguish(clear: false); } else { if ((Object)(object)((Component)this).transform.parent != (Object)null) { ((Component)this).transform.SetParent((Transform)null, true); } ((Component)this).transform.SetPositionAndRotation(_socket.position, _socket.rotation); } } FindParts(); UpdateGround(); DeflectFlames(); } private void UpdateGround() { //IL_001e: 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_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: 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_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_016b: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_0175: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: 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_01ba: Unknown result type (might be due to invalid IL or missing references) //IL_01bf: Unknown result type (might be due to invalid IL or missing references) //IL_01c4: 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_0191: 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_019c: 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) if (_fading) { return; } float deltaTime = Time.deltaTime; RaycastHit val = default(RaycastHit); if (Physics.Raycast(((Component)this).transform.position, ((Component)this).transform.forward, ref val, groundRange, LayerMask.op_Implicit(groundMask), (QueryTriggerInteraction)1)) { _missTime = 0f; if (!_hasGround) { _groundPoint = ((RaycastHit)(ref val)).point; _groundNormal = ((RaycastHit)(ref val)).normal; _impactVel = Vector3.zero; } else if (deltaTime > 0f) { _groundPoint = Vector3.SmoothDamp(_groundPoint, ((RaycastHit)(ref val)).point, ref _impactVel, impactSmoothTime, impactMaxSpeed, deltaTime); Vector3 val2 = Vector3.Slerp(_groundNormal, ((RaycastHit)(ref val)).normal, 1f - Mathf.Exp(-10f * deltaTime)); _groundNormal = ((Vector3)(ref val2)).normalized; } _hasGround = true; } else { _missTime += deltaTime; if (_missTime > impactLoseDelay) { _hasGround = false; } } bool hasGround = _hasGround; if ((Object)(object)groundFire == (Object)null) { return; } if (hasGround) { Vector3 val3 = Vector3.ProjectOnPlane(((Component)this).transform.forward, _groundNormal); if (((Vector3)(ref val3)).sqrMagnitude < 0.0001f) { val3 = Vector3.ProjectOnPlane(((Component)this).transform.up, _groundNormal); } groundFire.SetPositionAndRotation(_groundPoint + _groundNormal * 0.1f, Quaternion.LookRotation(val3, _groundNormal)); } for (int i = 0; i < _groundSystems.Length; i++) { ParticleSystem val4 = _groundSystems[i]; if (!((Object)(object)val4 == (Object)null)) { if (hasGround && !val4.isEmitting) { val4.Play(false); } else if (!hasGround && val4.isEmitting) { val4.Stop(false, (ParticleSystemStopBehavior)1); } } } if ((Object)(object)_groundLight != (Object)null) { ((Behaviour)_groundLight).enabled = hasGround; } } private void DeflectFlames() { //IL_00bf: 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_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_0136: 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_0145: 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_014f: Unknown result type (might be due to invalid IL or missing references) //IL_0151: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_015f: 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_017e: Unknown result type (might be due to invalid IL or missing references) //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_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_01af: 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_01de: Unknown result type (might be due to invalid IL or missing references) //IL_01ec: 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_020a: 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_0215: 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_0244: Unknown result type (might be due to invalid IL or missing references) //IL_0251: Unknown result type (might be due to invalid IL or missing references) //IL_0256: Unknown result type (might be due to invalid IL or missing references) if (!_hasGround || (Object)(object)flames == (Object)null || (Object)(object)_flamesRenderer == (Object)null) { return; } int particleCount = flames.particleCount; if (particleCount == 0) { return; } if (_buffer == null || _buffer.Length < particleCount) { _buffer = (Particle[])(object)new Particle[Mathf.Max(particleCount, 64)]; } int particles = flames.GetParticles(_buffer, particleCount); float lengthScale = _flamesRenderer.lengthScale; float velocityScale = _flamesRenderer.velocityScale; bool flag = false; for (int i = 0; i < particles; i++) { Vector3 velocity = ((Particle)(ref _buffer[i])).velocity; float magnitude = ((Vector3)(ref velocity)).magnitude; if (magnitude < 0.01f || Vector3.Dot(velocity, _groundNormal) >= 0f) { continue; } Vector3 val = velocity / magnitude; float num = ((Particle)(ref _buffer[i])).GetCurrentSize(flames) * lengthScale + magnitude * velocityScale; Vector3 val2 = ((Particle)(ref _buffer[i])).position + val * (num * 0.5f); if (Vector3.Dot(val2 - _groundPoint, _groundNormal) > 0f) { continue; } Vector3 val3 = Vector3.ProjectOnPlane(velocity, _groundNormal); if (((Vector3)(ref val3)).sqrMagnitude < 0.0001f) { val3 = Vector3.ProjectOnPlane(((Component)this).transform.forward, _groundNormal); } if (!(((Vector3)(ref val3)).sqrMagnitude < 0.0001f)) { ((Particle)(ref _buffer[i])).velocity = ((Vector3)(ref val3)).normalized * (magnitude * slideSpeedFactor); float num2 = Vector3.Dot(((Particle)(ref _buffer[i])).position - _groundPoint, _groundNormal); if (num2 < 0.3f) { ref Particle reference = ref _buffer[i]; ((Particle)(ref reference)).position = ((Particle)(ref reference)).position + _groundNormal * (0.3f - num2); } flag = true; } } if (flag) { flames.SetParticles(_buffer, particles); } } private void Update() { if (!_fading) { return; } _lightFadeTimer += Time.deltaTime; float num = Mathf.Clamp01(_lightFadeTimer / lightFadeSeconds); for (int i = 0; i < _lights.Length; i++) { if ((Object)(object)_lights[i] != (Object)null) { _lights[i].intensity = Mathf.Lerp(_lightStart[i], 0f, num); } } bool flag = false; for (int j = 0; j < _systems.Length; j++) { if ((Object)(object)_systems[j] != (Object)null && _systems[j].IsAlive(false)) { flag = true; break; } } bool flag2 = _lights.Length == 0 || _lightFadeTimer >= lightFadeSeconds; if (!flag && flag2) { Object.Destroy((Object)(object)((Component)this).gameObject); } } } internal static class DragonCreature { private const float SizeNoStars = 0.8f; private const float SizeOneStar = 0.9f; private const float SpeedNoStars = 1.15f; private const float SpeedOneStar = 1.075f; private const float FlySpeedNoStars = 1.075f; private const float FlySpeedOneStar = 1.0375f; private const string BundleName = "m2dragon"; private const string PrefabName = "M2Dragon"; private const string SaddlePrefabName = "SaddleM2Dragon"; private const string DeathVfxPrefabName = "M2Dragon_death_vfx"; private const string ReinsRopeMaterialName = "ReinsRope"; private const string ReinsLinePrefabName = "ReinsLine"; private const string BreathVfxPrefabName = "M2Dragon_breath_vfx_fire"; private const string TamingFood = "LoxMeat"; private const string BreathSfxPrefabName = "M2Dragon_breath_sfx"; private const string BreathSfxSource = "sfx_dragon_coldbreath_trailon"; private static GameObject s_breathSfx; private static bool s_breathSfxApplied; private const float VoicePitch = 0.8f; internal const float SpawnDistance = 30f; private static readonly List<GameObject> s_withPlaceholders = new List<GameObject>(); private static bool s_placeholdersResolved; private static bool s_deathSoundApplied; private const string SaddleSourceMaterial = "asksvinsaddle_mat"; private static readonly Color SaddleMetalColor = new Color(0.43f, 0.64f, 0.43f, 1f); private static GameObject s_saddlePrefab; private static Material s_saddleMaterial; private const float HeartsHeight = 4.5f; private static bool s_tameEffectsApplied; private const string CreatureShaderName = "Custom/Creature"; private const string CreatureShaderSource = "lox"; private static bool s_creatureShaderApplied; public static Material ReinsRopeMaterial { get; private set; } public static GameObject ReinsLinePrefab { get; private set; } internal static GameObject RoarSfx { get; private set; } internal static GameObject GrowlSfx { get; private set; } internal static GameObject Prefab { get; private set; } public static void Register() { Item.DefaultConfigurability = Configurability.Disabled; AssetBundle val = EmbeddedResources.LoadBundle(Assembly.GetExecutingAssembly(), "m2dragon"); if ((Object)(object)val == (Object)null) { Plugin.Log.LogError((object)"Embedded resource 'm2dragon' nicht gefunden oder nicht ladbar."); return; } GameObject val2 = LoadAsset<GameObject>(val, "M2Dragon"); if ((Object)(object)val2 == (Object)null) { val.Unload(false); return; } ReinsRopeMaterial = LoadAsset<Material>(val, "ReinsRope"); ReinsLinePrefab = LoadAsset<GameObject>(val, "ReinsLine"); GameObject val3 = LoadAsset<GameObject>(val, "M2Dragon_breath_vfx_fire"); if ((Object)(object)val3 != (Object)null) { s_withPlaceholders.Add(val3); val3.AddComponent<DragonFireWindowGuard>(); } s_breathSfx = LoadAsset<GameObject>(val, "M2Dragon_breath_sfx"); if ((Object)(object)s_breathSfx != (Object)null) { s_breathSfx.AddComponent<DragonFireWindowGuard>(); } RegisterCreature(val, val2); RegisterSaddleItem(val); RegisterDeathVfx(val); val.Unload(false); GameData.ObjectDbReady += ResolvePlaceholders; } private static void RegisterCreature(AssetBundle bundle, GameObject prefab) { //IL_00cf: Unknown result type (might be due to invalid IL or missing references) Prefab = prefab; s_withPlaceholders.Add(prefab); Humanoid component = prefab.GetComponent<Humanoid>(); if ((Object)(object)component != (Object)null) { GameObject[][] array = new GameObject[2][] { component.m_defaultItems, component.m_randomWeapon }; foreach (GameObject[] array2 in array) { if (array2 == null) { continue; } GameObject[] array3 = array2; foreach (GameObject val in array3) { if ((Object)(object)val != (Object)null && !s_withPlaceholders.Contains(val)) { s_withPlaceholders.Add(val); } } } } new Creature(bundle, "M2Dragon") { ConfigurationEnabled = false, FoodItems = "LoxMeat", Biome = (Biome)16, SpecificSpawnArea = SpawnArea.Center, RequiredAltitude = new CreatureManager.Range(1f, 1000f), SpawnChance = 5f, CheckSpawnInterval = 600, Maximum = 1, CanHaveStars = true }; ApplyStarSizes(prefab); } internal static float SizeForLevel(int level) { return (level <= 1) ? 0.8f : ((level == 2) ? 0.9f : 1f); } internal static float SpeedForLevel(int level) { return (level <= 1) ? 1.15f : ((level == 2) ? 1.075f : 1f); } internal static float FlySpeedForLevel(int level) { return (level <= 1) ? 1.075f : ((level == 2) ? 1.0375f : 1f); } private static void ApplyStarSizes(GameObject prefab) { //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Expected O, but got Unknown //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Expected O, but got Unknown //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) LevelEffects componentInChildren = prefab.GetComponentInChildren<LevelEffects>(true); if ((Object)(object)componentInChildren == (Object)null) { Plugin.Log.LogWarning((object)"LevelEffects fehlt im Prefab -- alle Drachen haben volle Groesse."); return; } componentInChildren.m_mainRender = null; componentInChildren.m_levelSetups = new List<LevelSetup> { new LevelSetup { m_scale = SizeForLevel(2) }, new LevelSetup { m_scale = SizeForLevel(3) } }; ((Component)componentInChildren).transform.localScale = Vector3.one * SizeForLevel(1); } private static T LoadAsset<T>(AssetBundle bundle, string name) where T : Object { T val = bundle.LoadAsset<T>(name); if ((Object)(object)val == (Object)null) { Plugin.Log.LogError((object)("'" + name + "' fehlt im Bundle 'm2dragon'.")); } return val; } private static void RegisterSaddleItem(AssetBundle bundle) { GameObject val = LoadAsset<GameObject>(bundle, "SaddleM2Dragon"); if (!((Object)(object)val == (Object)null)) { s_withPlaceholders.Add(val); s_saddlePrefab = val; Item item = new Item(val); item.Crafting.Add(CraftingTable.Workbench, 3); item.RequiredItems.Add("BlackMetal", 15); item.RequiredItems.Add("LinenThread", 20); item.RequiredItems.Add("LoxPelt", 6); } } private static void RegisterDeathVfx(AssetBundle bundle) { GameObject val = LoadAsset<GameObject>(bundle, "M2Dragon_death_vfx"); if (!((Object)(object)val == (Object)null)) { Prefabs.Register(val); s_withPlaceholders.Add(val); } } private static void ApplyDeathSound() { //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Expected O, but got Unknown Humanoid val = (((Object)(object)Prefab != (Object)null) ? Prefab.GetComponent<Humanoid>() : null); if (!s_deathSoundApplied && !((Object)(object)val == (Object)null)) { GameObject val2 = EffectCopy("sfx_dragon_death", "M2Dragon_death_sfx", 0.8f, networked: true); if (!((Object)(object)val2 == (Object)null)) { List<EffectData> list = new List<EffectData>(((Character)val).m_deathEffects.m_effectPrefabs) { new EffectData { m_prefab = val2 } }; ((Character)val).m_deathEffects.m_effectPrefabs = list.ToArray(); s_deathSoundApplied = true; } } } private static void ResolvePlaceholders() { ApplyCreatureShader(); ApplySaddleItem(); ApplyBreathSfx(); if ((Object)(object)RoarSfx == (Object)null) { RoarSfx = EffectCopy("sfx_dragon_alerted", "M2Dragon_roar_sfx", 0.8f, networked: false); } if ((Object)(object)GrowlSfx == (Object)null) { GrowlSfx = EffectCopy("sfx_dragon_idle", "M2Dragon_growl_sfx", 0.8f, networked: false); } ApplyTameEffects(); ApplyDeathSound(); if (!s_placeholdersResolved) { int num = 0; foreach (GameObject s_withPlaceholder in s_withPlaceholders) { num += MockReferences.Resolve(s_withPlaceholder); } s_placeholdersResolved = num == 0; } ApplySaddleColor(); } private static void ApplySaddleColor() { //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_00bd: Expected O, but got Unknown //IL_00c7: Unknown result type (might be due to invalid IL or missing references) GameObject[] array = (GameObject[])(object)new GameObject[2] { Prefab, s_saddlePrefab }; foreach (GameObject val in array) { if ((Object)(object)val == (Object)null) { continue; } Renderer[] componentsInChildren = val.GetComponentsInChildren<Renderer>(true); foreach (Renderer val2 in componentsInChildren) { Material[] sharedMaterials = val2.sharedMaterials; bool flag = false; for (int k = 0; k < sharedMaterials.Length; k++) { if (!((Object)(object)sharedMaterials[k] == (Object)null) && !(((Object)sharedMaterials[k]).name != "asksvinsaddle_mat")) { if ((Object)(object)s_saddleMaterial == (Object)null) { s_saddleMaterial = new Material(sharedMaterials[k]) { name = "M2Dragon_saddle_mat" }; s_saddleMaterial.SetColor("_MetalColor", SaddleMetalColor); } sharedMaterials[k] = s_saddleMaterial; flag = true; } } if (flag) { val2.sharedMaterials = sharedMaterials; } } } } private static void ApplySaddleItem() { Tameable val = (((Object)(object)Prefab != (Object)null) ? Prefab.GetComponent<Tameable>() : null); if (!((Object)(object)val == (Object)null) && !((Object)(object)ObjectDB.instance == (Object)null)) { GameObject itemPrefab = ObjectDB.instance.GetItemPrefab("SaddleM2Dragon"); val.m_saddleItem = (((Object)(object)itemPrefab != (Object)null) ? itemPrefab.GetComponent<ItemDrop>() : null); if ((Object)(object)val.m_saddleItem == (Object)null) { Plugin.Log.LogWarning((object)"Sattel-Item 'SaddleM2Dragon' nicht in ObjectDB gefunden -- Drache nicht sattelbar."); } } } private static GameObject EffectCopy(string source, string name, float pitch, bool networked) { GameObject val = Prefabs.Find(source); if ((Object)(object)val == (Object)null) { Plugin.Log.LogWarning((object)("'" + source + "' nicht gefunden -- '" + name + "' fehlt.")); return null; } GameObject val2 = Prefabs.Clone(val, name); if (!networked) { ZNetView[] componentsInChildren = val2.GetComponentsInChildren<ZNetView>(true); foreach (ZNetView val3 in componentsInChildren) { Object.DestroyImmediate((Object)(object)val3); } } ZSFX[] componentsInChildren2 = val2.GetComponentsInChildren<ZSFX>(true); foreach (ZSFX val4 in componentsInChildren2) { val4.m_minPitch *= pitch; val4.m_maxPitch *= pitch; } if (networked) { Prefabs.Register(val2); } return val2; } private static void ApplyTameEffects() { //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Expected O, but got Unknown //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Expected O, but got Unknown //IL_0161: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Expected O, but got Unknown //IL_0181: Unknown result type (might be due to invalid IL or missing references) //IL_0186: Unknown result type (might be due to invalid IL or missing references) //IL_018e: Expected O, but got Unknown //IL_00e2: 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) Tameable val = (((Object)(object)Prefab != (Object)null) ? Prefab.GetComponent<Tameable>() : null); if (s_tameEffectsApplied || (Object)(object)val == (Object)null) { return; } GameObject val2 = EffectCopy("fx_asksvin_soothed", "M2Dragon_hearts", 1f, networked: true); GameObject val3 = EffectCopy("fx_asksvin_tamed", "M2Dragon_tamed", 1f, networked: true); GameObject val4 = EffectCopy("sfx_dragon_idle", "M2Dragon_pet_sfx", 0.8f, networked: true); if ((Object)(object)val2 == (Object)null || (Object)(object)val3 == (Object)null || (Object)(object)val4 == (Object)null) { return; } GameObject[] array = (GameObject[])(object)new GameObject[2] { val2, val3 }; foreach (GameObject val5 in array) { Transform val6 = val5.transform.Find("hearts"); if ((Object)(object)val6 != (Object)null) { val6.localPosition = Vector3.up * 4.5f; } else { Plugin.Log.LogWarning((object)(((Object)val5).name + " ohne 'hearts' -- Herzchen bleiben an der Wurzel.")); } } val.m_petEffect.m_effectPrefabs = (EffectData[])(object)new EffectData[2] { new EffectData { m_prefab = val2 }, new EffectData { m_prefab = val4 } }; val.m_sootheEffect.m_effectPrefabs = (EffectData[])(object)new EffectData[1] { new EffectData { m_prefab = val2 } }; val.m_tamedEffect.m_effectPrefabs = (EffectData[])(object)new EffectData[1] { new EffectData { m_prefab = val3 } }; s_tameEffectsApplied = true; } private static void ApplyBreathSfx() { if (s_breathSfxApplied || (Object)(object)s_breathSfx == (Object)null) { return; } GameObject val = Prefabs.Find("sfx_dragon_coldbreath_trailon"); if ((Object)(object)val == (Object)null) { Plugin.Log.LogWarning((object)"'sfx_dragon_coldbreath_trailon' nicht gefunden -- Feueratem bleibt stumm."); return; } ZSFX[] componentsInChildren = s_breathSfx.GetComponentsInChildren<ZSFX>(true); foreach (ZSFX val2 in componentsInChildren) { Transform val3 = (((Object)(object)((Component)val2).transform == (Object)(object)s_breathSfx.transform) ? val.transform : val.transform.Find(((Object)val2).name)); ZSFX val4 = (((Object)(object)val3 != (Object)null) ? ((Component)val3).GetComponent<ZSFX>() : null); if ((Object)(object)val4 == (Object)null) { Plugin.Log.LogWarning((object)("sfx_dragon_coldbreath_trailon: kein Gegenstueck fuer '" + ((Object)val2).name + "'.")); continue; } val2.m_audioClips = val4.m_audioClips; AudioSource component = ((Component)val2).GetComponent<AudioSource>(); AudioSource component2 = ((Component)val4).GetComponent<AudioSource>(); if ((Object)(object)component != (Object)null && (Object)(object)component2 != (Object)null) { component.outputAudioMixerGroup = component2.outputAudioMixerGroup; } } s_breathSfxApplied = true; } private static void ApplyCreatureShader() { if (s_creatureShaderApplied || (Object)(object)Prefab == (Object)null) { return; } Material val = AssetLookup.Find<Material>("lox"); if ((Object)(object)val == (Object)null || (Object)(object)val.shader == (Object)null || ((Object)val.shader).name != "Custom/Creature") { Plugin.Log.LogWarning((object)"Valheims 'Custom/Creature' ueber 'lox' nicht gefunden -- naechster Versuch beim naechsten Weltstart."); return; } int num = 0; Renderer[] componentsInChildren = Prefab.GetComponentsInChildren<Renderer>(true); foreach (Renderer val2 in componentsInChildren) { if (val2 is ParticleSystemRenderer) { continue; } Material[] sharedMaterials = val2.sharedMaterials; foreach (Material val3 in sharedMaterials) { if (!((Object)(object)val3 == (Object)null) && NeedsCreatureShader(val3.shader)) { val3.shader = val.shader; num++; } } } s_creatureShaderApplied = true; Plugin.Log.LogInfo((object)string.Format("{0} Materialien auf Valheims '{1}' umgestellt.", num, "Custom/Creature")); } private static bool NeedsCreatureShader(Shader shader) { return (Object)(object)shader == (Object)null || ((Object)shader).name == "Custom/Creature" || ((Object)shader).name == "Hidden/InternalErrorShader"; } } internal class DragonFireWindowGuard : MonoBehaviour { private void OnTransformParentChanged() { Transform parent = ((Component)this).transform.parent; if (!((Object)(object)parent == (Object)null)) { DragonAnimEvents componentInParent = ((Component)parent).GetComponentInParent<DragonAnimEvents>(); if ((Object)(object)componentInParent != (Object)null && !componentInParent.InFireState) { Object.Destroy((Object)(object)((Component)this).gameObject); } } } } internal enum LandingPhase { None, Approach, Flare } internal struct FlightInput { internal bool Ridden; internal bool AiControl; internal bool LocalRider; internal Speed Speed; internal Vector3 ControlDir; internal float Skill; internal bool Exhausted; internal bool TakeoffAnim; internal bool Breathing; internal bool AirBreath; internal bool AirBreathFlap; internal float AirBreathSpeed; internal Vector3 AirBreathSteer; } internal struct FlightStep { internal bool Flapping; internal bool Hovering; internal bool Braking; internal float Altitude; internal float RawLift; internal float VelOffset; internal float AirSink; } internal readonly struct FlareTarget { internal readonly float TouchdownIn; internal readonly float Sink; internal FlareTarget(float touchdownIn, float sink) { TouchdownIn = touchdownIn; Sink = sink; } } internal sealed class DragonFlightModel { private const float FlapSpeed = 14f; private const float TurnSpeed = 25f; internal const float MaxPitchUp = 45f; internal const float MaxPitchDown = 55f; private const float GlideTrimSpeed = 12.5f; private const float GlideRatio = 12.5f; private const float AirBrake = 4f; private const float AirBrakeSink = 1.5f; private const float HoverBrake = 6f; private const float VerticalSmoothing = 1.5f; private const float StallSinkRate = 3f; private const float TakeoffLiftVelocity = 10f; private const float TakeoffSmoothing = 4f; private const float TakeoffForwardThrust = 8f; private const float GroundEffectHeight = 6f; private const float GroundEffectLift = 2f; private const float RidgeLift = 1.5f; private const float RidgeHeight = 40f; private const float FlapCameraShake = 0.35f; private const float SkillFlapSpeed = 0.2f; private const float SkillAgility = 0.25f; private const float SkillAerodynamics = 0.2f; private const float WindInfluence = 8f; private const float WindBlendTime = 1f; private const float DescendVelocity = 3f; private const float FlareVerticalAccel = 12f; private const float PitchTurnSpeed = 35f; private const float YawResponse = 2.5f; private const float RiderYawRampTime = 0.21f; private const float AiYawRampTime = 0.5f; private const float PitchSmoothTime = 0.3f; private const float PitchLevelDoneAngle = 0.01f; private const float MinTurnSpeedFactor = 0.6f; private const float MaxTurnSpeedFactor = 1.3f; private const float FlyAcceleration = 6f; private const float LandingApproachSpeed = 16f; private const float GravityPull = 7f; private const float MinFlySpeed = 4f; private const float MaxDiveSpeed = 32f; private const float LiftVelocity = 10f; private const float LiftMeanTime = 3f; private const float StallSpeedThreshold = 5f; private const float StallPitchThreshold = 0.6f; private const float StallExitPitchDeg = -5f; private const float FlapShakeThreshold = 0.4f; private static readonly int s_liftCurveHash = Animator.StringToHash("LiftCurve"); private static readonly int s_flapBlendHash = Animator.StringToHash("flap_blend"); private const float FlapBlendSmoothTime = 0.18f; private const float FlapThrustRampTime = 0.5f; private static readonly int s_flappingHash = Animator.StringToHash("flapping"); private readonly Transform _transform; private readonly Character _character; private readonly Rigidbody _body; private readonly Animator _animator; private readonly DragonLevelScaling _level; private readonly DragonGroundProbe _probe; private float _pitchDeg; private float _yawVelocity; private float _yawStepTime = -1f; private float _yawMaxAcceleration = float.PositiveInfinity; private float _pitchVelocity; private float _flySpeed; private float _windBlend; private float _velOffsetSmoothed; private bool _glideStalled; private float _liftMean = 0.2f; private float _riderSkill; private float _flapBlendShown; private float _flapBlendVelocity; private float _flapThrust; private float _prevLift; private bool _hovering; internal float ClimbRate { get; private set; } internal bool Flapping { get; private set; } internal float CameraSpeedFactor { get; private set; } internal bool Hovering => _hovering; internal float FlySpeed => _flySpeed; private float Lift => _animator.GetFloat(s_liftCurveHash); private float FlySpeedFactor => _level.FlySpeedFactor; internal float TrimSpeed => 12.5f * FlySpeedFactor; internal DragonFlightModel(Transform transform, Character character, Rigidbody body, Animator animator, DragonLevelScaling level, DragonGroundProbe probe) { _transform = transform; _character = character; _body = body; _animator = animator; _level = level; _probe = probe; } private static float AeroFactor(float skill) { return 1f - 0.2f * skill; } private static float SkillSpeedFactor(float skill) { return 1f + 0.2f * skill; } private static float SkillAgilityFactor(float skill) { return 1f + 0.25f * skill; } private float TrimSink(float skill) { return TrimSpeed / 12.5f * AeroFactor(skill); } private float GlideSink(float speed, float skill) { float trimSpeed = TrimSpeed; float num = TrimSink(skill); return (speed >= trimSpeed) ? num : (num * (0.5f + 0.5f * trimSpeed / Mathf.Max(speed, 0.1f))); } private float AirDragAccel(float speed, float skill) { float trimSpeed = TrimSpeed; return 7f * TrimSink(skill) / (trimSpeed * trimSpeed * trimSpeed) * speed * speed; } private float PitchFromTransform() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) return Mathf.Clamp(Mathf.Asin(Mathf.Clamp(_transform.forward.y, -1f, 1f)) * 57.29578f, -55f, 45f); } internal void ResetForTakeoff() { _pitchDeg = 0f; _pitchVelocity = 0f; StopMotion(); } internal void ResetAfterLanding() { StopMotion(); CameraSpeedFactor = 0f; } private void StopMotion() { _flySpeed = 0f; _flapThrust = 0f; _velOffsetSmoothed = 0f; _windBlend = 0f; SetFlapping(flapping: false); _glideStalled = false; _hovering = false; } internal void TakeOver(bool flying) { //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_006b: 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_0086: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) Flapping = false; _flapThrust = 0f; _glideStalled = false; _velOffsetSmoothed = 0f; _windBlend = 0f; _pitchDeg = PitchFromTransform(); _pitchVelocity = 0f; _yawVelocity = 0f; if (flying) { Vector3 val = (((Object)(object)_body != (Object)null) ? _body.linearVelocity : Vector3.zero); _flySpeed = Mathf.Clamp(Vector3.Dot(val, _transform.forward), 4f, 32f); _velOffsetSmoothed = val.y - _transform.forward.y * _flySpeed; } } internal void StartHover() { _hovering = true; } internal void UpdateGrounded(float dt) { CameraSpeedFactor = 0f; if (LevelPitch(dt)) { ApplyPitch(); } } private bool LevelPitch(float dt) { if (_pitchDeg == 0f) { return false; } _pitchDeg = Mathf.SmoothDamp(_pitchDeg, 0f, ref _pitchVelocity, 0.3f, 35f, dt); if (Mathf.Abs(_pitchDeg) < 0.01f) { _pitchDeg = 0f; _pitchVelocity = 0f; } return true; } internal void PrepareBody() { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) Flapping = false; _character.m_maxAirAltitude = _transform.position.y; _body.useGravity = false; _body.angularVelocity = Vector3.zero; } internal void StepTakeoffHold(float dt, bool localRider) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0042: 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_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: 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_005c: 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_0067: 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_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: 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) float lift = Lift; float num = UpdateTakeoffClimb(lift, dt); Vector3 linearVelocity = _body.linearVelocity; Vector3 val = new Vector3(_transform.forward.x, 0f, _transform.forward.z); Vector3 normalized = ((Vector3)(ref val)).normalized; Vector3 val2 = Vector3.MoveTowards(new Vector3(linearVelocity.x, 0f, linearVelocity.z), normalized * _flySpeed, 20f * dt); _body.linearVelocity = val2 + Vector3.up * num; UpdateFlapShake(lift, active: true, localRider); SetFlapping(flapping: false); SetFlightAnimatorParams(Vector3.Dot(val2, normalized), 0f); } private float UpdateTakeoffClimb(float lift, float dt) { float num = Mathf.Max(0f, lift); _flySpeed = Mathf.Min(_flySpeed + num * 8f * dt, 32f); _velOffsetSmoothed = Mathf.Lerp(_velOffsetSmoothed, num * 10f, 1f - Mathf.Exp(-4f * dt)); return _velOffsetSmoothed; } internal FlightStep BeginStep(in FlightInput input, LandingPhase landing, float dt) { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Invalid comparison between Unknown and I4 //IL_0078: 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_00c8: 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_011a: Unknown result type (might be due to invalid IL or missing references) bool flag = landing != LandingPhase.None; float lift = Lift; bool airBreath = input.AirBreath; bool flag2 = (Flapping = ((!input.Ridden && !input.AiControl) ? (airBreath && input.AirBreathFlap) : ((int)input.Speed == 2 && !input.Exhausted && !input.Breathing))); bool takeoffAnim = input.TakeoffAnim; if (_hovering && (!input.Ridden || (int)input.Speed != 0 || input.Exhausted || flag)) { _hovering = false; } bool flag4 = (_hovering || (input.AiControl && (int)input.Speed == 0 && !flag)) && !takeoffAnim; bool flag5 = input.Ridden && (int)input.Speed == 0 && !flag && !flag4; float altitude = _probe.GetAltitude(); UpdateFlapShake(lift, flag2 || takeoffAnim, input.LocalRider); float skill = (_riderSkill = input.Skill); float num = lift; float num2 = Vector3.Dot(_transform.forward, Vector3.up); float num3 = ((lift > 0f && _flySpeed < 5f && Mathf.Abs(num2) > 0.6f) ? 0.25f : 1f); float num4 = 0f; float num5 = 0f; if (!flag4) { if (flag2) { _liftMean = Mathf.Lerp(_liftMean, num, 1f - Mathf.Exp((0f - dt) / 3f)); num4 += (num - _liftMean) * num3 * 10f; } else { num5 -= GlideSink(_flySpeed, skill); } } if (!flag && !takeoffAnim && !flag4) { float num6 = GroundEffect(altitude); if (flag2) { num4 += num6 * 2f; } else { num5 *= 1f - num6; } num4 += RidgeUpdraft(altitude); } if (flag5) { num5 -= 1.5f; } bool flag6 = !flag2 && !flag4 && !flag && !takeoffAnim && !airBreath && _flySpeed <= 5f && _pitchDeg > 0f; bool flag7 = flag2 || flag4 || flag || takeoffAnim || airBreath || _pitchDeg <= -5f; _glideStalled = (_glideStalled ? (!flag7) : flag6); if (_glideStalled) { num5 -= 3f; } num4 += num5; return new FlightStep { Flapping = flag2, Hovering = flag4, Braking = flag5, Altitude = altitude, RawLift = num, VelOffset = num4, AirSink = num5 }; } internal void EndStep(in FlightInput input, in FlightStep step, LandingPhase landing, in FlareTarget flare, float dt) { //IL_02c2: Unknown result type (might be due to invalid IL or missing references) //IL_0322: Unknown result type (might be due to invalid IL or missing references) //IL_02f8: 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_0372: Unknown result type (might be due to invalid IL or missing references) //IL_0377: Unknown result type (might be due to invalid IL or missing references) //IL_032a: Unknown result type (might be due to invalid IL or missing references) //IL_03a2: Unknown result type (might be due to invalid IL or missing references) //IL_0399: Unknown result type (might be due to invalid IL or missing refer