Decompiled source of ValheimRAFT v2.1.1
plugins\ValheimRAFT.dll
Decompiled a year ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Dynamic; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using Advize_PlantEasily; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using Components; using HarmonyLib; using Jotunn; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Extensions; using Jotunn.GUI; using Jotunn.Managers; using Jotunn.Utils; using Microsoft.CodeAnalysis; using PlanBuild.Blueprints; using PlanBuild.Blueprints.Components; using PlanBuild.Plans; using Registry; using SentryUnityWrapper; using UnityEngine; using UnityEngine.Events; using UnityEngine.U2D; using UnityEngine.UI; using ValheimRAFT; using ValheimRAFT.Patches; using ValheimRAFT.UI; using ValheimRAFT.Util; using ValheimVehicles.ConsoleCommands; using ValheimVehicles.Prefabs; using ValheimVehicles.Prefabs.Registry; using ValheimVehicles.Propulsion.Rudder; using ValheimVehicles.Propulsion.Sail; using ValheimVehicles.Utis; using ValheimVehicles.Vehicles; using ValheimVehicles.Vehicles.Components; using ValheimVehicles.Vehicles.Enums; using ValheimVehicles.Vehicles.Interfaces; using ValheimVehicles.Vehicles.Structs; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("ValheimRAFT")] [assembly: AssemblyDescription("Valheim Mod for building on the sea")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Virtualize LLC")] [assembly: AssemblyProduct("ValheimRAFT")] [assembly: AssemblyCopyright("Copyright © 2023-2024, GNU-v3 licensed")] [assembly: Guid("6015B165-2627-40A7-8CA1-3E6B6CD7CB49")] [assembly: AssemblyFileVersion("2.1.1")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("2.1.1.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.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 Components { public class LeverComponent { } public class VehicleDebugGui : SingletonBehaviour<VehicleDebugGui> { private GUIStyle? myButtonStyle; private string ShipMovementOffsetText; private Vector3 _shipMovementOffset; private Vector3 GetShipMovementOffset() { //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) string[] array = ShipMovementOffsetText.Split(new char[1] { ',' }); if (array.Length != 3) { return new Vector3(0f, 0f, 0f); } float num = float.Parse(array[0]); float num2 = float.Parse(array[1]); float num3 = float.Parse(array[2]); return new Vector3(num, num2, num3); } private void OnGUI() { //IL_0039: 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_0025: Expected O, but got Unknown if (myButtonStyle == null) { myButtonStyle = new GUIStyle(GUI.skin.button) { fontSize = 50 }; } GUILayout.BeginArea(new Rect(500f, 10f, 200f, 200f), myButtonStyle); if (GUILayout.Button("collider debugger", Array.Empty<GUILayoutOption>())) { Logger.LogMessage((object)"Collider debugger called, \nblue = BlockingCollider for collisions and keeping boat on surface, \ngreen is float collider for pushing the boat upwards, typically it needs to be below or at same level as BlockingCollider to prevent issues, \nYellow is onboardtrigger for calculating if player is onboard"); VehicleDebugHelpers vehicleDebugHelpers = VehicleDebugHelpers.GetOnboardVehicleDebugHelper(); if (!Object.op_Implicit((Object)(object)vehicleDebugHelpers)) { vehicleDebugHelpers = VehicleDebugHelpers.GetOnboardMBRaftDebugHelper(); } if (!Object.op_Implicit((Object)(object)vehicleDebugHelpers)) { return; } vehicleDebugHelpers?.StartRenderAllCollidersLoop(); } if (GUILayout.Button("raftcreative", Array.Empty<GUILayoutOption>())) { CreativeModeConsoleCommand.RunCreativeModeCommand("raftcreative"); } if (GUILayout.Button("activatePendingPieces", Array.Empty<GUILayoutOption>())) { VehicleDebugHelpers.GetVehicleController()?.ActivatePendingPiecesCoroutine(); } if (GUILayout.Button("Flip Ship", Array.Empty<GUILayoutOption>())) { VehicleDebugHelpers.GetOnboardVehicleDebugHelper()?.FlipShip(); } GUILayout.EndArea(); } } } namespace a { public class ObservableList { } } namespace Registry { public class ShipKeelPrefab : IRegisterPrefab { public static readonly ShipKeelPrefab Instance = new ShipKeelPrefab(); public void Register(PrefabManager prefabManager, PieceManager pieceManager) { //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Expected O, but got Unknown //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: 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_00ba: Expected O, but got Unknown //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Expected O, but got Unknown GameObject val = prefabManager.CreateClonedPrefab("ValheimVehicles_ShipKeel", LoadValheimVehicleAssets.ShipKeelAsset); PrefabRegistryHelpers.HoistSnapPointsToPrefab(val, val.transform); PrefabRegistryHelpers.AddNetViewWithPersistence(val); PrefabRegistryHelpers.SetWearNTear(val); PrefabRegistryHelpers.AddPieceForPrefab("ValheimVehicles_ShipKeel", val); PrefabRegistryHelpers.PieceData valueSafe = GeneralExtensions.GetValueSafe<string, PrefabRegistryHelpers.PieceData>(PrefabRegistryHelpers.PieceDataDictionary, "ValheimVehicles_ShipKeel"); PieceConfig val2 = new PieceConfig(); val2.PieceTable = "Hammer"; val2.Description = valueSafe.Description; val2.Icon = LoadValheimVehicleAssets.VehicleSprites.GetSprite("keel"); val2.Category = "Raft"; val2.Enabled = true; val2.Requirements = (RequirementConfig[])(object)new RequirementConfig[1] { new RequirementConfig { Amount = 10, Item = "Wood", Recover = true } }; pieceManager.AddPiece(new CustomPiece(val, false, val2)); } } public class VehiclePiecesPrefab : IRegisterPrefab { public static readonly VehiclePiecesPrefab Instance = new VehiclePiecesPrefab(); public static GameObject VehiclePiecesContainer => PrefabManager.Instance.GetPrefab("ValheimVehicles_piecesContainer"); public void Register(PrefabManager prefabManager, PieceManager pieceManager) { prefabManager.CreateClonedPrefab("ValheimVehicles_piecesContainer", LoadValheimVehicleAssets.VehiclePiecesAsset); } } } namespace ValheimVehicles.Vehicles { public class AirVehicle { } public class BaseVehicleController : MonoBehaviour { internal enum InitializationState { Pending, Complete, Created } public static readonly KeyValuePair<int, int> MBParentHash = ZDO.GetHashZDOID("MBParent"); public static readonly int MBCharacterParentHash = StringExtensionMethods.GetStableHashCode("MBCharacterParent"); public static readonly int MBCharacterOffsetHash = StringExtensionMethods.GetStableHashCode("MBCharacterOffset"); public static readonly int MBParentIdHash = StringExtensionMethods.GetStableHashCode("MBParentId"); public static readonly int MBPositionHash = StringExtensionMethods.GetStableHashCode("MBPosition"); public static readonly int MBRotationHash = StringExtensionMethods.GetStableHashCode("MBRotation"); public static readonly int MBRotationVecHash = StringExtensionMethods.GetStableHashCode("MBRotationVec"); public static readonly int MBPieceCount = StringExtensionMethods.GetStableHashCode("MBPieceCount"); public static readonly string ZdoKeyBaseVehicleInitState = "ValheimVehicles_BaseVehicle_Initialized"; public static Dictionary<int, BaseVehicleController> ActiveInstances = new Dictionary<int, BaseVehicleController>(); public static Dictionary<int, List<ZNetView>> m_pendingPieces = new Dictionary<int, List<ZNetView>>(); public static Dictionary<int, List<ZDO>> m_allPieces = new Dictionary<int, List<ZDO>>(); public static Dictionary<int, List<ZDOID>> m_dynamicObjects = new Dictionary<int, List<ZDOID>>(); public WaterVehicleController waterVehicleController; public BaseVehicleController instance; internal Rigidbody? m_rigidbody; internal Rigidbody? m_syncRigidbody; internal List<ZNetView> m_pieces = new List<ZNetView>(); internal List<ZNetView> m_hullPieces = new List<ZNetView>(); internal List<MastComponent> m_mastPieces = new List<MastComponent>(); internal List<SailComponent> m_sailPieces = new List<SailComponent>(); internal List<Bed> m_bedPieces = new List<Bed>(); internal List<RudderComponent> m_rudderPieces = new List<RudderComponent>(); internal List<SteeringWheelComponent> _steeringWheelPieces = new List<SteeringWheelComponent>(); internal List<ZNetView> m_portals = new List<ZNetView>(); internal List<RopeLadderComponent> m_ladders = new List<RopeLadderComponent>(); internal List<BoardingRampComponent> m_boardingRamps = new List<BoardingRampComponent>(); private InitializationState _baseVehicleInitializationState; internal float ShipContainerMass; internal float ShipMass; public static bool hasDebug = false; public int numberOfTier1Sails; public int numberOfTier2Sails; public int numberOfTier3Sails; public int numberOfTier4Sails; public float customSailsArea; public float totalSailArea; private Vector2i m_sector; private Vector2i m_serverSector; private Bounds _vehicleBounds; private Bounds _hullBounds; public BoxCollider m_blockingcollider = new BoxCollider(); internal BoxCollider m_floatcollider = new BoxCollider(); internal BoxCollider m_onboardcollider = new BoxCollider(); public bool isCreative; private int _persistentZdoId; private Stopwatch vehicleInitializationTimer = new Stopwatch(); public bool m_statsOverride; private static bool itemsRemovedDuringWait; private Coroutine? _pendingPiecesCoroutine; private Coroutine? _serverUpdatePiecesCoroutine; private Coroutine? _bedUpdateCoroutine; public ZNetView m_nview { get; set; } internal InitializationState BaseVehicleInitState { get { return _baseVehicleInitializationState; } set { if (!Enum.IsDefined(typeof(InitializationState), value)) { throw new InvalidEnumArgumentException("value", (int)value, typeof(InitializationState)); } _baseVehicleInitializationState = value; OnBaseVehicleInitializationStateChange(value); } } internal float TotalMass => ShipContainerMass + ShipMass; public virtual IVehicleShip VehicleInstance { get; set; } public int PersistentZdoId => GetPersistentID(); public List<ZNetView> GetCurrentPieces() { return m_pieces.ToList(); } private void OnBaseVehicleInitializationStateChange(InitializationState state) { if (state == InitializationState.Complete) { ActivatePendingPiecesCoroutine(); } } public void LoadInitState() { if (!Object.op_Implicit((Object)(object)m_nview)) { BaseVehicleInitState = InitializationState.Pending; } bool @bool = m_nview.GetZDO().GetBool(ZdoKeyBaseVehicleInitState, false); BaseVehicleInitState = (@bool ? InitializationState.Complete : InitializationState.Created); } public void SetInitComplete() { m_nview.GetZDO().Set(ZdoKeyBaseVehicleInitState, true); BaseVehicleInitState = InitializationState.Complete; } public void SetColliders(VehicleShip vehicleInstance) { //IL_0036: 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_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00da: 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) BoxCollider[] componentsInChildren = ((Component)((Component)vehicleInstance).transform).GetComponentsInChildren<BoxCollider>(); m_onboardcollider = (BoxCollider)(((object)((IEnumerable<BoxCollider>)componentsInChildren).FirstOrDefault((Func<BoxCollider, bool>)((BoxCollider k) => ((Object)((Component)k).gameObject).name.Contains("VehicleShip_OnboardTriggerCollider")))) ?? ((object)new BoxCollider())); m_floatcollider = vehicleInstance.FloatCollider; m_blockingcollider = (BoxCollider)(((object)((IEnumerable<BoxCollider>)componentsInChildren).FirstOrDefault((Func<BoxCollider, bool>)((BoxCollider k) => ((Object)((Component)k).gameObject).name.Contains("VehicleShip_BlockingCollider")))) ?? ((object)new BoxCollider())); if ((Object)(object)m_onboardcollider != (Object)null) { ((Component)m_onboardcollider).transform.localScale = new Vector3(1f, 1f, 1f); } if ((Object)(object)m_floatcollider != (Object)null) { ((Component)m_floatcollider).transform.localScale = new Vector3(1f, 1f, 1f); } if ((Object)(object)m_blockingcollider != (Object)null) { ((Component)m_blockingcollider).transform.localScale = new Vector3(1f, 1f, 1f); ((Component)m_blockingcollider).gameObject.layer = ValheimRaftPlugin.CustomRaftLayer; ((Component)((Component)m_blockingcollider).transform.parent).gameObject.layer = ValheimRaftPlugin.CustomRaftLayer; } } public void FireErrorOnNull(Collider obj, string name) { if (!Object.op_Implicit((Object)(object)obj)) { Logger.LogError((object)("BaseVehicleError: collider not initialized for <" + name + ">")); } } public void ValidateInitialization() { FireErrorOnNull((Collider)(object)m_floatcollider, "VehicleShip_FloatCollider"); FireErrorOnNull((Collider)(object)m_blockingcollider, "VehicleShip_BlockingCollider"); FireErrorOnNull((Collider)(object)m_onboardcollider, "VehicleShip_OnboardTriggerCollider"); } private void HideGhostContainer() { IVehicleShip vehicleInstance = VehicleInstance; if (vehicleInstance != null) { vehicleInstance.Instance.GhostContainer.SetActive(false); } } public void Awake() { instance = this; hasDebug = ValheimRaftPlugin.Instance.HasDebugBase.Value; vehicleInitializationTimer.Start(); if (!Object.op_Implicit((Object)(object)m_rigidbody)) { m_rigidbody = ((Component)this).GetComponent<Rigidbody>(); } } public void UpdateBedSpawn() { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) foreach (Bed bedPiece in m_bedPieces) { if (Object.op_Implicit((Object)(object)bedPiece.m_nview)) { Vector3 position = bedPiece.m_nview.m_zdo.GetPosition(); if (!(position == bedPiece.m_spawnPoint.position)) { bedPiece.m_spawnPoint.position = position; } } } } private IEnumerable UpdateBedSpawnWorker() { UpdateBedSpawn(); yield return (object)new WaitForSeconds(3f); } public void InitializeBaseVehicleValuesWhenReady() { if (!((Object)(object)m_nview == (Object)null)) { if (_persistentZdoId == 0) { _persistentZdoId = GetPersistentID(); } LoadInitState(); HideGhostContainer(); if (!Object.op_Implicit((Object)(object)GeneralExtensions.GetValueSafe<int, BaseVehicleController>(ActiveInstances, PersistentZdoId))) { ActiveInstances.Add(PersistentZdoId, this); } } } public virtual void Start() { ValidateInitialization(); if (Object.op_Implicit((Object)(object)ZNet.instance)) { Logger.LogInfo((object)$"BaseVehicleController pieces {m_pieces.Count}"); Logger.LogInfo((object)$"BaseVehicleController pendingPieces {m_pendingPieces.Count}"); Logger.LogInfo((object)$"BaseVehicleController allPieces {m_allPieces.Count}"); if (ZNet.instance.IsDedicated()) { _serverUpdatePiecesCoroutine = ((MonoBehaviour)this).StartCoroutine("UpdatePiecesInEachSectorWorker"); } ActivatePendingPiecesCoroutine(); } } protected int GetPersistentID() { if (!Object.op_Implicit((Object)(object)m_nview)) { _persistentZdoId = 0; return _persistentZdoId; } if (m_nview.GetZDO() == null) { _persistentZdoId = 0; return _persistentZdoId; } _persistentZdoId = ZDOPersistentID.Instance.GetOrCreatePersistentID(m_nview.GetZDO()); return _persistentZdoId; } private void OnDisable() { vehicleInitializationTimer.Stop(); if (_serverUpdatePiecesCoroutine != null) { ((MonoBehaviour)this).StopCoroutine(_serverUpdatePiecesCoroutine); } } private void OnEnable() { GetPersistentID(); vehicleInitializationTimer.Restart(); ZNetView component = ((Component)this).GetComponent<ZNetView>(); if (Object.op_Implicit((Object)(object)component)) { m_nview = component; } ActivatePendingPiecesCoroutine(); if (Object.op_Implicit((Object)(object)ZNet.instance) && ZNet.instance.IsDedicated() && _serverUpdatePiecesCoroutine == null) { _serverUpdatePiecesCoroutine = ((MonoBehaviour)this).StartCoroutine("UpdatePiecesInEachSectorWorker"); } } public void CleanUp() { RemovePlayerFromBoat(); if (Object.op_Implicit((Object)(object)GeneralExtensions.GetValueSafe<int, BaseVehicleController>(ActiveInstances, _persistentZdoId))) { ActiveInstances.Remove(_persistentZdoId); } if (_pendingPiecesCoroutine != null) { ((MonoBehaviour)this).StopCoroutine(_pendingPiecesCoroutine); } if (_serverUpdatePiecesCoroutine != null) { ((MonoBehaviour)this).StopCoroutine(_serverUpdatePiecesCoroutine); } if (!Object.op_Implicit((Object)(object)ZNetScene.instance) || _persistentZdoId == 0) { return; } foreach (ZNetView piece in m_pieces) { if (Object.op_Implicit((Object)(object)piece)) { ((Component)piece).transform.SetParent((Transform)null); AddInactivePiece(_persistentZdoId, piece, null); } } } public virtual void SyncRigidbodyStats(float drag, float angularDrag) { if (Object.op_Implicit((Object)(object)m_rigidbody) && Object.op_Implicit((Object)(object)m_syncRigidbody) && !m_statsOverride && Object.op_Implicit((Object)(object)VehicleInstance?.Instance)) { m_rigidbody.angularDrag = angularDrag; m_syncRigidbody.angularDrag = angularDrag; m_rigidbody.drag = drag; m_syncRigidbody.drag = drag; m_syncRigidbody.mass = TotalMass; m_rigidbody.mass = TotalMass; } } private void Sync() { //IL_002c: 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) if (Object.op_Implicit((Object)(object)m_syncRigidbody) && Object.op_Implicit((Object)(object)m_rigidbody)) { m_rigidbody.MovePosition(((Component)m_syncRigidbody).transform.position); m_rigidbody.MoveRotation(((Component)m_syncRigidbody).transform.rotation); } } public void Update() { if (Object.op_Implicit((Object)(object)m_nview)) { Sync(); if (ValheimRaftPlugin.Instance.ForceShipOwnerUpdatePerFrame.Value && m_nview.IsOwner()) { Client_UpdateAllPieces(); } } } public void FixedUpdate() { Sync(); Client_UpdateAllPieces(); } public void LateUpdate() { Sync(); } public void Client_UpdateAllPieces() { //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_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_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_0086: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) Vector2i zone = ZoneSystem.instance.GetZone(((Component)this).transform.position); if (zone == m_sector) { return; } if (m_sector != m_serverSector) { ServerSyncAllPieces(); } m_sector = zone; for (int i = 0; i < m_pieces.Count; i++) { ZNetView val = m_pieces[i]; if (!Object.op_Implicit((Object)(object)val)) { Logger.LogError((object)$"Error found with m_pieces: netview {val}"); m_pieces.RemoveAt(i); i--; } else if (((Component)this).transform.position != ((Component)val).transform.position) { ZDO zdo = val.m_zdo; if (zdo != null) { zdo.SetPosition(((Component)this).transform.position); } } } } public void ServerSyncAllPieces() { if (_serverUpdatePiecesCoroutine == null) { _serverUpdatePiecesCoroutine = ((MonoBehaviour)this).StartCoroutine(UpdatePiecesInEachSectorWorker()); } } public void UpdatePieces(List<ZDO> list) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0011: 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_0017: 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_002a: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_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_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) Vector3 position = ((Component)this).transform.position; Vector2i zone = ZoneSystem.instance.GetZone(position); if (m_serverSector == zone) { return; } if (!((Vector2i)(ref zone)).Equals(m_sector)) { m_sector = zone; } m_serverSector = zone; for (int i = 0; i < list.Count; i++) { ZDO val = list[i]; if (!(val.GetSector() == zone)) { if (val.GetInt(MBParentIdHash, 0) != _persistentZdoId) { list.FastRemoveAt(i); i--; } else { val.SetPosition(position); } } } } private IEnumerator UpdatePiecesWorker(List<ZDO> list) { UpdatePieces(list); yield return (object)new WaitForFixedUpdate(); } public IEnumerator UpdatePiecesInEachSectorWorker() { while (((Behaviour)this).isActiveAndEnabled) { if (!Object.op_Implicit((Object)(object)m_nview)) { yield return (object)new WaitUntil((Func<bool>)(() => Object.op_Implicit((Object)(object)m_nview))); } List<ZDO> value; bool flag = m_allPieces.TryGetValue(_persistentZdoId, out value); if (value == null || !flag) { yield return (object)new WaitForSeconds(Math.Max(2f, ValheimRaftPlugin.Instance.ServerRaftUpdateZoneInterval.Value)); continue; } yield return UpdatePiecesWorker(value); yield return (object)new WaitForEndOfFrame(); } } internal float GetColliderBottom() { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) return ((Component)m_blockingcollider).transform.position.y + m_blockingcollider.center.y - m_blockingcollider.size.y / 2f; } public static void AddInactivePiece(int id, ZNetView netView, BaseVehicleController? instance) { if (hasDebug) { Logger.LogDebug((object)$"addInactivePiece called with {id} for {((Object)netView).name}"); } if ((Object)(object)instance != (Object)null && ((Behaviour)instance).isActiveAndEnabled && ActiveInstances.TryGetValue(id, out BaseVehicleController value)) { value.ActivatePiece(netView); return; } if (!m_pendingPieces.TryGetValue(id, out List<ZNetView> value2)) { value2 = new List<ZNetView>(); m_pendingPieces.Add(id, value2); } value2.Add(netView); WearNTear component = ((Component)netView).GetComponent<WearNTear>(); if (Object.op_Implicit((Object)(object)component)) { ((Behaviour)component).enabled = false; } } public void UpdateMass(ZNetView netView, bool isRemoving = false) { if (!Object.op_Implicit((Object)(object)netView)) { if (hasDebug) { Logger.LogDebug((object)"NetView is invalid skipping mass update"); } return; } Piece component = ((Component)netView).GetComponent<Piece>(); if (!Object.op_Implicit((Object)(object)component)) { if (hasDebug) { Logger.LogDebug((object)"unable to fetch piece data from netViewPiece this could be a raft piece erroring."); } return; } float num = ComputePieceWeight(component, isRemoving); if (isRemoving) { ShipMass -= num; } else { ShipMass += num; } if (Object.op_Implicit((Object)(object)m_rigidbody)) { m_rigidbody.mass = 1000f + TotalMass; } if (Object.op_Implicit((Object)(object)m_syncRigidbody)) { m_syncRigidbody.mass = 1000f + TotalMass; } } public void DebouncedRebuildBounds() { ((MonoBehaviour)this).CancelInvoke("RebuildBounds"); ((MonoBehaviour)this).Invoke("RebuildBounds", 1f); } public void RemovePiece(ZNetView netView) { if (((Object)netView).name.Contains("ValheimVehicles_WaterVehicleShip") || !m_pieces.Remove(netView)) { return; } UpdateMass(netView, isRemoving: true); DebouncedRebuildBounds(); if (ShipHulls.IsHull(((Component)netView).gameObject)) { m_hullPieces.Remove(netView); } SailComponent component = ((Component)netView).GetComponent<SailComponent>(); if (Object.op_Implicit((Object)(object)component)) { m_sailPieces.Remove(component); } MastComponent component2 = ((Component)netView).GetComponent<MastComponent>(); if (Object.op_Implicit((Object)(object)component2)) { m_mastPieces.Remove(component2); } RudderComponent component3 = ((Component)netView).GetComponent<RudderComponent>(); if (Object.op_Implicit((Object)(object)component3)) { m_rudderPieces.Remove(component3); if (Object.op_Implicit((Object)(object)VehicleInstance?.Instance) && m_rudderPieces.Count > 0) { SetShipWakeBounds(); } } SteeringWheelComponent component4 = ((Component)netView).GetComponent<SteeringWheelComponent>(); if (Object.op_Implicit((Object)(object)component4)) { _steeringWheelPieces.Remove(component4); } Bed component5 = ((Component)netView).GetComponent<Bed>(); if (Object.op_Implicit((Object)(object)component5)) { m_bedPieces.Remove(component5); } BoardingRampComponent component6 = ((Component)netView).GetComponent<BoardingRampComponent>(); if (Object.op_Implicit((Object)(object)component6)) { m_boardingRamps.Remove(component6); } if (Object.op_Implicit((Object)(object)((Component)netView).GetComponent<TeleportWorld>())) { m_portals.Remove(netView); } RopeLadderComponent component7 = ((Component)netView).GetComponent<RopeLadderComponent>(); if (Object.op_Implicit((Object)(object)component7)) { m_ladders.Remove(component7); component7.m_mbroot = null; component7.baseVehicleController = null; } } private void UpdateStats() { } public void ComputeAllShipContainerItemWeight() { if (!ValheimRaftPlugin.Instance.HasShipContainerWeightCalculations.Value && ShipContainerMass != 0f) { ShipContainerMass = 0f; return; } Container[] componentsInChildren = ((Component)this).GetComponentsInChildren<Container>(); float num = 0f; Container[] array = componentsInChildren; foreach (Container container in array) { num += ComputeContainerWeight(container); } ShipContainerMass = num; } private float ComputeContainerWeight(Container container, bool isRemoving = false) { Inventory inventory = container.GetInventory(); if (inventory != null) { float totalWeight = inventory.GetTotalWeight(); if (hasDebug) { Logger.LogDebug((object)$"containerWeight {totalWeight} name: {((Object)container).name}"); } if (isRemoving) { return 0f - totalWeight; } return totalWeight; } return 0f; } private float ComputePieceWeight(Piece piece, bool isRemoving) { //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_007c: 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_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)piece)) { return 0f; } string name = ((Object)piece).name; if (ValheimRaftPlugin.Instance.HasShipContainerWeightCalculations.Value) { Container component = ((Component)piece).GetComponent<Container>(); if (Object.op_Implicit((Object)(object)component)) { ShipContainerMass += ComputeContainerWeight(component, isRemoving); } } float num = 1f; if (((Component)piece).transform.localScale != new Vector3(1f, 1f, 1f)) { num = ((Component)piece).transform.localScale.x * ((Component)piece).transform.localScale.y * ((Component)piece).transform.localScale.z; if (hasDebug) { Logger.LogDebug((object)$"ValheimRAFT ComputeShipItemWeight() found piece that does not have a 1,1,1 local scale piece: {name} scale: {((Component)piece).transform.localScale}, the 3d localScale will be multiplied by the area of this vector instead of 1x1x1"); } } if (name == PrefabRegistryHelpers.GetPieceNameFromPrefab("ValheimVehicles_Ship_Hull_Wood")) { return 20f; } if (name == PrefabRegistryHelpers.GetPieceNameFromPrefab("ValheimVehicles_Ship_Hull_Iron")) { return 80f; } if (name == PrefabRegistryHelpers.GetPieceNameFromPrefab("ValheimVehicles_Ship_Hull_Rib_Wood")) { return 180f; } if (name == PrefabRegistryHelpers.GetPieceNameFromPrefab("ValheimVehicles_Ship_Hull_Rib_Iron")) { return 720f; } if (name == "wood_floor_1x1") { return 1f * num; } if (name.Contains("wood")) { return 4f * num; } if (name.Contains("stone_")) { return 12f * num; } if (name.Contains("blackmarble")) { return 8f * num; } if (name.Contains("blastfurnace") || name.Contains("charcoal_kiln") || name.Contains("forge") || name.Contains("smelter")) { return 20f * num; } return 2f * num; } public void DestroyPiece(WearNTear wnt) { if (Object.op_Implicit((Object)(object)wnt)) { if (((Object)wnt).name.Contains("ValheimVehicles_WaterVehicleShip")) { return; } ZNetView component = ((Component)wnt).GetComponent<ZNetView>(); RemovePiece(component); UpdatePieceCount(); totalSailArea = 0f; } if (GetPieceCount() <= 0 && !((Object)(object)m_nview == (Object)null) && (Object)(object)VehicleInstance?.Instance != (Object)null) { WearNTear component2 = ((Component)VehicleInstance.Instance).GetComponent<WearNTear>(); if (Object.op_Implicit((Object)(object)component2)) { component2.Destroy((HitData)null); } } } public void RemovePlayerFromBoat() { foreach (Player item in from t in Player.GetAllPlayers() where Object.op_Implicit((Object)(object)t) && (Object)(object)((Component)t).transform.parent == (Object)(object)((Component)this).transform select t) { ((Component)item).transform.SetParent((Transform)null); } } public void DestroyVehicle() { WearNTear component = ((Component)instance).GetComponent<WearNTear>(); RemovePlayerFromBoat(); if (CanDestroyVehicle(m_nview)) { if (Object.op_Implicit((Object)(object)component)) { component.Destroy((HitData)null); } else if (Object.op_Implicit((Object)(object)instance)) { Object.Destroy((Object)(object)instance); } if ((Object)(object)((Component)instance).gameObject != (Object)(object)((Component)this).gameObject) { Object.Destroy((Object)(object)((Component)this).gameObject); } } } public void ActivatePendingPiecesCoroutine() { if (hasDebug) { Logger.LogDebug((object)$"ActivatePendingPiecesCoroutine(): pendingPieces count: {m_pendingPieces.Count}"); } if (_pendingPiecesCoroutine == null && (BaseVehicleInitState == InitializationState.Complete || m_pendingPieces.Count != 0)) { _pendingPiecesCoroutine = ((MonoBehaviour)this).StartCoroutine("ActivatePendingPieces"); } } public IEnumerator ActivatePendingPieces() { Vector3 val2 = default(Vector3); while (true) { Stopwatch stopwatch2 = vehicleInitializationTimer; if (stopwatch2 == null || stopwatch2.ElapsedMilliseconds >= 50000 || !stopwatch2.IsRunning) { break; } if (!Object.op_Implicit((Object)(object)m_nview) || (Object)(object)m_nview == (Object)null) { yield return (object)new WaitUntil((Func<bool>)(() => Object.op_Implicit((Object)(object)m_nview))); } if (BaseVehicleInitState != InitializationState.Complete) { yield return (object)new WaitUntil((Func<bool>)(() => BaseVehicleInitState == InitializationState.Complete)); } ZNetView nview = m_nview; if (((nview != null) ? nview.GetZDO() : null) == null) { yield return (object)new WaitUntil((Func<bool>)delegate { ZNetView nview2 = m_nview; return ((nview2 != null) ? nview2.GetZDO() : null) != null; }); } int id = ZDOPersistentID.Instance.GetOrCreatePersistentID(m_nview.GetZDO()); m_pendingPieces.TryGetValue(id, out List<ZNetView> list); if (list != null && list.Count > 0) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); foreach (ZNetView item in list) { if (Object.op_Implicit((Object)(object)item)) { if (hasDebug) { Logger.LogDebug((object)$"ActivatePendingPieces obj: {item} {((Object)item).name}"); } ActivatePiece(item); if (!ZNetScene.instance.InLoadingScreen() && stopwatch.ElapsedMilliseconds >= 10) { yield return (object)new WaitForEndOfFrame(); stopwatch.Restart(); } } else if (hasDebug) { Logger.LogDebug((object)$"ActivatePendingPieces obj is not valid {item}"); } } list.Clear(); m_pendingPieces.Remove(id); } if (hasDebug) { Logger.LogDebug((object)$"Ship Size calc is: m_bounds {_vehicleBounds} bounds size {((Bounds)(ref _vehicleBounds)).size}"); } m_dynamicObjects.TryGetValue(_persistentZdoId, out List<ZDOID> value); if (value != null && value.Count > 0) { if (hasDebug) { Logger.LogDebug((object)$"m_dynamicObjects is valid: {value.Count}"); } for (int i = 0; i < value.Count; i++) { GameObject val = ZNetScene.instance.FindInstance(value[i]); if (!Object.op_Implicit((Object)(object)val)) { continue; } ZNetView componentInParent = val.GetComponentInParent<ZNetView>(); if (!Object.op_Implicit((Object)(object)componentInParent) || componentInParent.m_zdo == null) { continue; } if (ZDOExtraData.s_vec3.TryGetValue(componentInParent.m_zdo.m_uid, out var value2)) { if (value2.TryGetValue(MBCharacterOffsetHash, ref val2)) { ((Component)componentInParent).transform.position = val2 + ((Component)this).transform.position; } val2 = default(Vector3); } ZDOExtraData.RemoveInt(componentInParent.m_zdo.m_uid, MBCharacterParentHash); ZDOExtraData.RemoveVec3(componentInParent.m_zdo.m_uid, MBCharacterOffsetHash); value2 = null; } m_dynamicObjects.Remove(_persistentZdoId); yield return null; } yield return (object)new WaitForSeconds(1f); list = null; } vehicleInitializationTimer.Stop(); } public static bool AddDynamicParent(ZNetView source, GameObject target) { //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) BaseVehicleController componentInParent = target.GetComponentInParent<BaseVehicleController>(); if (!Object.op_Implicit((Object)(object)componentInParent)) { return false; } source.m_zdo.Set(MBCharacterParentHash, componentInParent.PersistentZdoId, false); source.m_zdo.Set(MBCharacterOffsetHash, ((Component)source).transform.position - ((Component)componentInParent).transform.position); return true; } public float GetTotalSailArea() { if (totalSailArea != 0f || !Object.op_Implicit((Object)(object)ValheimRaftPlugin.Instance) || (m_mastPieces.Count == 0 && m_sailPieces.Count == 0)) { return totalSailArea; } totalSailArea = 0f; customSailsArea = 0f; numberOfTier1Sails = 0; numberOfTier2Sails = 0; numberOfTier3Sails = 0; numberOfTier4Sails = 0; bool value = ValheimRaftPlugin.Instance.EnableCustomPropulsionConfig.Value; foreach (MastComponent item in m_mastPieces.ToList()) { if (!Object.op_Implicit((Object)(object)item)) { m_mastPieces.Remove(item); } else if (((Object)item).name.StartsWith("MBRaftMast")) { numberOfTier1Sails++; float num = (value ? ValheimRaftPlugin.Instance.SailTier1Area.Value : SailAreaForce.Tier1); totalSailArea += (float)numberOfTier1Sails * num; } else if (((Object)item).name.StartsWith("MBKarveMast")) { numberOfTier2Sails++; float num2 = (value ? ValheimRaftPlugin.Instance.SailTier2Area.Value : SailAreaForce.Tier2); totalSailArea += (float)numberOfTier2Sails * num2; } else if (((Object)item).name.StartsWith("MBVikingShipMast")) { numberOfTier3Sails++; float num3 = (value ? ValheimRaftPlugin.Instance.SailTier3Area.Value : SailAreaForce.Tier3); totalSailArea += (float)numberOfTier3Sails * num3; } else if (((Object)item).name.StartsWith("ValheimVehicles_DrakkalMast")) { numberOfTier4Sails++; float num4 = (value ? ValheimRaftPlugin.Instance.SailTier4Area.Value : SailAreaForce.Tier4); totalSailArea += (float)numberOfTier4Sails * num4; } } SailComponent[] componentsInChildren = ((Component)this).GetComponentsInChildren<SailComponent>(); if (componentsInChildren.Length != 0) { SailComponent[] array = componentsInChildren; foreach (SailComponent sailComponent in array) { if (Object.op_Implicit((Object)(object)sailComponent)) { customSailsArea += sailComponent.GetSailArea(); } } if (hasDebug) { Logger.LogDebug((object)$"CustomSailsArea {customSailsArea}"); } float val = (value ? ValheimRaftPlugin.Instance.SailCustomAreaTier1Multiplier.Value : SailAreaForce.CustomTier1AreaForceMultiplier); totalSailArea += customSailsArea * Math.Max(0.1f, val); } if (totalSailArea != 0f && !ValheimRaftPlugin.Instance.HasShipWeightCalculations.Value) { totalSailArea = Math.Min(ValheimRaftPlugin.Instance.MaxSailSpeed.Value, totalSailArea); } return totalSailArea; } public float GetSailingForce() { float num = GetTotalSailArea(); if (!ValheimRaftPlugin.Instance.HasShipWeightCalculations.Value) { return num; } float value = ValheimRaftPlugin.Instance.MassPercentageFactor.Value; float val = ValheimRaftPlugin.Instance.SpeedCapMultiplier.Value * num / (TotalMass / value); float val2 = Math.Min(ValheimRaftPlugin.Instance.MaxSailSpeed.Value, val); return Math.Min(ValheimRaftPlugin.Instance.MaxPropulsionSpeed.Value, val2); } public static void InitZdo(ZDO zdo) { //IL_0082: Unknown result type (might be due to invalid IL or missing references) if (zdo.m_prefab == StringExtensionMethods.GetStableHashCode("ValheimVehicles_WaterVehicleShip")) { return; } int parentID = GetParentID(zdo); if (parentID != 0) { if (!m_allPieces.TryGetValue(parentID, out List<ZDO> value)) { value = new List<ZDO>(); m_allPieces.Add(parentID, value); } if (value.Contains(zdo)) { return; } value.Add(zdo); } int @int = zdo.GetInt(MBCharacterParentHash, 0); if (@int != 0) { if (!m_dynamicObjects.TryGetValue(@int, out List<ZDOID> value2)) { value2 = new List<ZDOID>(); m_dynamicObjects.Add(@int, value2); } value2.Add(zdo.m_uid); } } public static void RemoveZDO(ZDO zdo) { int parentID = GetParentID(zdo); if (parentID != 0 && m_allPieces.TryGetValue(parentID, out List<ZDO> value)) { value.FastRemove(zdo); itemsRemovedDuringWait = true; } } private static int GetParentID(ZDO zdo) { //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_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0072: 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_008f: Unknown result type (might be due to invalid IL or missing references) int num = zdo.GetInt(MBParentIdHash, 0); if (num == 0) { ZDOID zDOID = zdo.GetZDOID(MBParentHash); if (zDOID != ZDOID.None) { ZDO zDO = ZDOMan.instance.GetZDO(zDOID); num = ((zDO == null) ? ZDOPersistentID.ZDOIDToId(zDOID) : ZDOPersistentID.Instance.GetOrCreatePersistentID(zDO)); zdo.Set(MBParentIdHash, num, false); int mBRotationVecHash = MBRotationVecHash; Quaternion quaternion = zdo.GetQuaternion(MBRotationHash, Quaternion.identity); zdo.Set(mBRotationVecHash, ((Quaternion)(ref quaternion)).eulerAngles); zdo.RemoveZDOID(MBParentHash); ZDOHelper.Remove<Quaternion>(ZDOExtraData.s_quats, zDOID, MBRotationHash); } } return num; } public static void InitPiece(ZNetView netView) { if (((Object)netView).name == "ValheimVehicles_WaterVehicleShip(Clone)") { return; } Rigidbody componentInChildren = ((Component)netView).GetComponentInChildren<Rigidbody>(); if (Object.op_Implicit((Object)(object)componentInChildren) && !componentInChildren.isKinematic) { return; } int parentID = GetParentID(netView.m_zdo); if (parentID == 0) { return; } GameObject gameObject = ZDOPersistentID.Instance.GetGameObject(parentID); if (Object.op_Implicit((Object)(object)gameObject)) { VehicleShip component = gameObject.GetComponent<VehicleShip>(); if (!((Object)(object)component == (Object)null) && !((Object)(object)component.VehicleController.Instance == (Object)null)) { component.Instance.VehicleController.Instance.ActivatePiece(netView); } } else { AddInactivePiece(parentID, netView, null); } } public void ActivatePiece(ZNetView netView) { //IL_002a: 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_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)netView)) { ((Component)netView).transform.SetParent(((Component)this).transform); ((Component)netView).transform.localPosition = netView.m_zdo.GetVec3(MBPositionHash, Vector3.zero); ((Component)netView).transform.localRotation = Quaternion.Euler(netView.m_zdo.GetVec3(MBRotationVecHash, Vector3.zero)); WearNTear component = ((Component)netView).GetComponent<WearNTear>(); if (Object.op_Implicit((Object)(object)component)) { ((Behaviour)component).enabled = true; } AddPiece(netView); } } public void AddTemporaryPiece(Piece piece) { ((Component)piece).transform.SetParent(((Component)this).transform); } public void AddNewPiece(Piece piece) { if (!Object.op_Implicit((Object)(object)piece)) { Logger.LogError((object)"piece does not exist"); return; } if (!Object.op_Implicit((Object)(object)piece.m_nview)) { Logger.LogError((object)"m_nview does not exist on piece"); return; } if (hasDebug) { Logger.LogDebug((object)"Added new piece is valid"); } AddNewPiece(piece.m_nview); } public static bool CanDestroyVehicle(ZNetView netView) { if (!Object.op_Implicit((Object)(object)netView)) { return false; } VehicleShip component = ((Component)netView).GetComponent<VehicleShip>(); List<ZNetView> value; bool flag = m_pendingPieces.TryGetValue(component.VehicleController.Instance.GetPersistentID(), out value); bool flag2 = component.VehicleController.Instance.GetPieceCount() != 0; if (value != null && flag && value.Count > 0) { return false; } return !flag2; } public void FixPieceMeshes(ZNetView netView) { //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Expected O, but got Unknown MeshRenderer[] componentsInChildren = ((Component)netView).GetComponentsInChildren<MeshRenderer>(true); foreach (MeshRenderer val in componentsInChildren) { Material[] materials = ((Renderer)val).materials; foreach (Material val2 in materials) { if (((Object)val2).name.Contains("blackmarble")) { val2.SetFloat("_TriplanarLocalPos", 1f); } } if (!Object.op_Implicit((Object)(object)((Renderer)val).sharedMaterial)) { continue; } Material[] sharedMaterials = ((Renderer)val).sharedMaterials; for (int k = 0; k < sharedMaterials.Length; k++) { Material val3 = new Material(sharedMaterials[k]); if (((Object)sharedMaterials[k]).name.Contains("blackmarble")) { val3.SetFloat("_TriplanarLocalPos", 1f); } val3.SetFloat("_RippleDistance", 0f); val3.SetFloat("_ValueNoise", 0f); sharedMaterials[k] = val3; } ((Renderer)val).sharedMaterials = sharedMaterials; } } public void AddNewPiece(ZNetView netView) { //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0084: 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_00a2: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)netView)) { Logger.LogError((object)"netView does not exist"); return; } if (m_pieces.Contains(netView)) { Logger.LogWarning((object)("NetView already is added. name: " + ((Object)netView).name)); return; } int pieceCount = GetPieceCount(); ((Component)netView).transform.SetParent(((Component)this).transform); if (netView.m_zdo != null) { netView.m_zdo.Set(MBParentIdHash, PersistentZdoId, false); ZDO zdo = netView.m_zdo; int mBRotationVecHash = MBRotationVecHash; Quaternion localRotation = ((Component)netView).transform.localRotation; zdo.Set(mBRotationVecHash, ((Quaternion)(ref localRotation)).eulerAngles); netView.m_zdo.Set(MBPositionHash, ((Component)netView).transform.localPosition); } if (netView.GetZDO() == null) { Logger.LogError((object)"NetView has no valid ZDO returning"); return; } AddPiece(netView); InitZdo(netView.GetZDO()); if (pieceCount == 0 && GetPieceCount() == 1) { SetInitComplete(); } } public void OnAddSteeringWheelDestroyPrevious(ZNetView netView, SteeringWheelComponent steeringWheelComponent) { List<SteeringWheelComponent> list = _steeringWheelPieces.ToList(); if (list.Count <= 0) { return; } foreach (WearNTear item in list.Select((SteeringWheelComponent wheel) => ((Component)wheel).GetComponent<WearNTear>())) { item.Destroy((HitData)null); } } public void AddPiece(ZNetView netView) { //IL_01f5: Unknown result type (might be due to invalid IL or missing references) //IL_0205: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)netView)) { Logger.LogError((object)"netView does not exist but somehow called AddPiece()"); return; } totalSailArea = 0f; m_pieces.Add(netView); UpdatePieceCount(); WearNTear component = ((Component)netView).GetComponent<WearNTear>(); if (Object.op_Implicit((Object)(object)component) && ValheimRaftPlugin.Instance.MakeAllPiecesWaterProof.Value) { component.m_noRoofWear = false; } if (ShipHulls.IsHull(((Component)netView).gameObject)) { m_hullPieces.Add(netView); } CultivatableComponent component2 = ((Component)netView).GetComponent<CultivatableComponent>(); if (Object.op_Implicit((Object)(object)component2)) { component2.UpdateMaterial(); } MastComponent component3 = ((Component)netView).GetComponent<MastComponent>(); if (Object.op_Implicit((Object)(object)component3)) { m_mastPieces.Add(component3); } SailComponent component4 = ((Component)netView).GetComponent<SailComponent>(); if (Object.op_Implicit((Object)(object)component4)) { m_sailPieces.Add(component4); } Bed component5 = ((Component)netView).GetComponent<Bed>(); if (Object.op_Implicit((Object)(object)component5)) { m_bedPieces.Add(component5); } BoardingRampComponent component6 = ((Component)netView).GetComponent<BoardingRampComponent>(); if (Object.op_Implicit((Object)(object)component6)) { component6.ForceRampUpdate(); m_boardingRamps.Add(component6); } RudderComponent component7 = ((Component)netView).GetComponent<RudderComponent>(); if (Object.op_Implicit((Object)(object)component7)) { m_rudderPieces.Add(component7); SetShipWakeBounds(); } SteeringWheelComponent component8 = ((Component)netView).GetComponent<SteeringWheelComponent>(); if (Object.op_Implicit((Object)(object)component8)) { OnAddSteeringWheelDestroyPrevious(netView, component8); _steeringWheelPieces.Add(component8); component8.InitializeControls(netView, VehicleInstance); } if (Object.op_Implicit((Object)(object)((Component)netView).GetComponent<TeleportWorld>())) { m_portals.Add(netView); } RopeLadderComponent component9 = ((Component)netView).GetComponent<RopeLadderComponent>(); if (Object.op_Implicit((Object)(object)component9)) { m_ladders.Add(component9); component9.baseVehicleController = instance; } FixPieceMeshes(netView); UpdateMass(netView); DebouncedRebuildBounds(); Rigidbody[] componentsInChildren = ((Component)netView).GetComponentsInChildren<Rigidbody>(); foreach (Rigidbody val in componentsInChildren) { if (val.isKinematic) { Object.Destroy((Object)(object)val); } } if (hasDebug) { Logger.LogDebug((object)$"After Adding Piece: {((Object)netView).name}, Ship Size calc is: m_bounds {_vehicleBounds} bounds size {((Bounds)(ref _vehicleBounds)).size}"); } } private void UpdatePieceCount() { if (Object.op_Implicit((Object)(object)m_nview) && m_nview.m_zdo != null) { m_nview.m_zdo.Set(MBPieceCount, m_pieces.Count, false); } } private void UpdateShipBounds() { OnBoundsChangeUpdateShipColliders(); } private void OnShipBoundsChange() { ((MonoBehaviour)this).CancelInvoke("UpdateShipBounds"); ((MonoBehaviour)this).Invoke("UpdateShipBounds", 0.1f); } private void SetShipWakeBounds() { //IL_00bc: 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_00d1: 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_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0084: 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_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)VehicleInstance?.Instance?.ShipEffectsObj == (Object)null)) { RudderComponent rudderComponent = m_rudderPieces.First(); Bounds bounds; if ((Object)(object)rudderComponent == (Object)null) { Transform transform = VehicleInstance.Instance.ShipEffectsObj.transform; float x = ((Component)m_floatcollider).transform.localPosition.x; bounds = ((Collider)m_floatcollider).bounds; float y = ((Bounds)(ref bounds)).center.y; bounds = ((Collider)m_floatcollider).bounds; transform.localPosition = new Vector3(x, y, ((Bounds)(ref bounds)).min.z); } else { Transform transform2 = VehicleInstance.Instance.ShipEffectsObj.transform; float x2 = ((Component)rudderComponent).transform.localPosition.x; bounds = ((Collider)m_floatcollider).bounds; transform2.localPosition = new Vector3(x2, ((Bounds)(ref bounds)).center.y, ((Component)rudderComponent).transform.localPosition.z); } } } private float GetAverageFloatHeightFromHulls() { //IL_001a: 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_004e: 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_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_0102: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) if (m_hullPieces.Count <= 0) { return 0.2f; } _hullBounds = default(Bounds); float num = 0f; foreach (ZNetView hullPiece in m_hullPieces) { Bounds? val = EncapsulateColliders(((Bounds)(ref _hullBounds)).center, ((Bounds)(ref _hullBounds)).size, ((Component)hullPiece).gameObject); num += ((Component)hullPiece).transform.localPosition.y; if (val.HasValue) { _hullBounds = val.Value; } } return ValheimRaftPlugin.Instance.HullFloatationColliderLocation.Value switch { ValheimRaftPlugin.HullFloatation.Average => num / (float)m_hullPieces.Count, ValheimRaftPlugin.HullFloatation.Bottom => ((Bounds)(ref _hullBounds)).min.y, ValheimRaftPlugin.HullFloatation.Top => ((Bounds)(ref _hullBounds)).max.y, _ => ((Bounds)(ref _hullBounds)).center.y, }; } private void RotateVehicleForwardPosition() { //IL_003e: Unknown result type (might be due to invalid IL or missing references) if (VehicleInstance != null && _steeringWheelPieces.Count > 0) { SteeringWheelComponent steeringWheelComponent = _steeringWheelPieces.First(); if (((Behaviour)steeringWheelComponent).enabled) { VehicleInstance.Instance.UpdateShipDirection(((Component)steeringWheelComponent).transform.localRotation); } } } public void RebuildBounds() { //IL_0039: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)m_floatcollider) || !Object.op_Implicit((Object)(object)m_onboardcollider) || !Object.op_Implicit((Object)(object)m_blockingcollider)) { return; } RotateVehicleForwardPosition(); Physics.SyncTransforms(); _vehicleBounds = default(Bounds); foreach (ZNetView piece in m_pieces) { EncapsulateBounds(((Component)piece).gameObject); } OnBoundsChangeUpdateShipColliders(); } public void OnBoundsChangeUpdateShipColliders() { //IL_0041: 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_0074: 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_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_014b: 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_017a: Unknown result type (might be due to invalid IL or missing references) //IL_0190: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_01be: 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_01de: Unknown result type (might be due to invalid IL or missing references) //IL_02de: Unknown result type (might be due to invalid IL or missing references) //IL_02f0: Unknown result type (might be due to invalid IL or missing references) //IL_02fd: Unknown result type (might be due to invalid IL or missing references) //IL_030e: Unknown result type (might be due to invalid IL or missing references) //IL_031a: Unknown result type (might be due to invalid IL or missing references) //IL_032c: 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_0228: Unknown result type (might be due to invalid IL or missing references) //IL_023f: Unknown result type (might be due to invalid IL or missing references) //IL_0256: Unknown result type (might be due to invalid IL or missing references) //IL_026d: Unknown result type (might be due to invalid IL or missing references) //IL_0284: Unknown result type (might be due to invalid IL or missing references) //IL_029b: Unknown result type (might be due to invalid IL or missing references) //IL_02b2: Unknown result type (might be due to invalid IL or missing references) //IL_02c9: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)m_blockingcollider) || !Object.op_Implicit((Object)(object)m_floatcollider) || !Object.op_Implicit((Object)(object)m_onboardcollider)) { Logger.LogWarning((object)"Ship colliders updated but the ship was unable to access colliders on ship object. Likely cause is ZoneSystem destroying the ship"); return; } float averageFloatHeightFromHulls = GetAverageFloatHeightFromHulls(); Vector3 val = default(Vector3); ((Vector3)(ref val))..ctor(((Bounds)(ref _vehicleBounds)).center.x, averageFloatHeightFromHulls - 0.2f, ((Bounds)(ref _vehicleBounds)).center.z); Vector3 val2 = default(Vector3); ((Vector3)(ref val2))..ctor(Mathf.Max(4f, ((Bounds)(ref _vehicleBounds)).size.x), m_floatcollider.size.y, Mathf.Max(4f, ((Bounds)(ref _vehicleBounds)).size.z)); float num = Math.Min(Math.Max(((Bounds)(ref _vehicleBounds)).size.y * 1.2f, ((Bounds)(ref _vehicleBounds)).size.y + 1f), ((Bounds)(ref _vehicleBounds)).size.y + 5f) - m_floatcollider.size.y; Vector3 localPosition = default(Vector3); ((Vector3)(ref localPosition))..ctor(((Bounds)(ref _vehicleBounds)).center.x, num / 2f, ((Bounds)(ref _vehicleBounds)).center.z); Vector3 size = default(Vector3); ((Vector3)(ref size))..ctor(Mathf.Max(4f, ((Bounds)(ref _vehicleBounds)).size.x), num, Mathf.Max(4f, ((Bounds)(ref _vehicleBounds)).size.z)); float num2 = val.y + 0.2f; Vector3 localPosition2 = default(Vector3); ((Vector3)(ref localPosition2))..ctor(((Bounds)(ref _vehicleBounds)).center.x, num2, ((Bounds)(ref _vehicleBounds)).center.z); Vector3 size2 = default(Vector3); ((Vector3)(ref size2))..ctor(Mathf.Max(4f, ((Bounds)(ref _vehicleBounds)).size.x), val2.y, Mathf.Max(4f, ((Bounds)(ref _vehicleBounds)).size.z)); if (ValheimRaftPlugin.Instance.HullCollisionOnly.Value && ((Bounds)(ref _hullBounds)).size != Vector3.zero) { localPosition2.x = ((Bounds)(ref _hullBounds)).center.x; localPosition2.z = ((Bounds)(ref _hullBounds)).center.z; size2.x = ((Bounds)(ref _hullBounds)).size.x; size2.z = ((Bounds)(ref _hullBounds)).size.z; val.x = ((Bounds)(ref _hullBounds)).center.x; val.z = ((Bounds)(ref _hullBounds)).center.z; val2.x = ((Bounds)(ref _hullBounds)).size.x; val2.z = ((Bounds)(ref _hullBounds)).size.z; } m_blockingcollider.size = size2; ((Component)m_blockingcollider).transform.localPosition = localPosition2; m_floatcollider.size = val2; ((Component)m_floatcollider).transform.localPosition = val; m_onboardcollider.size = size; ((Component)m_onboardcollider).transform.localPosition = localPosition; } public void IgnoreShipColliders(List<Collider> colliders) { foreach (Collider collider in colliders) { if (Object.op_Implicit((Object)(object)m_floatcollider)) { Physics.IgnoreCollision(collider, (Collider)(object)m_floatcollider, true); } if (Object.op_Implicit((Object)(object)m_blockingcollider)) { Physics.IgnoreCollision(collider, (Collider)(object)m_blockingcollider, true); } if (Object.op_Implicit((Object)(object)m_onboardcollider)) { Physics.IgnoreCollision(collider, (Collider)(object)m_onboardcollider, true); } } } public static Bounds? TransformColliderGlobalBoundsToLocal(Collider collider) { //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_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_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_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_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_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_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) Bounds bounds = collider.bounds; Vector3 val = ((Bounds)(ref bounds)).center; float magnitude = ((Vector3)(ref val)).magnitude; val = ((Component)collider).transform.position; float magnitude2 = ((Vector3)(ref val)).magnitude; if (Mathf.Abs(magnitude - magnitude2) > 5f) { Vector3 val2 = ((Component)((Component)collider).transform.root).transform.InverseTransformPoint(((Component)collider).transform.position); bounds = collider.bounds; return new Bounds(val2, ((Bounds)(ref bounds)).size); } Transform transform = ((Component)((Component)collider).transform.root).transform; bounds = collider.bounds; Vector3 val3 = transform.InverseTransformPoint(((Bounds)(ref bounds)).center); bounds = collider.bounds; Vector3 size = ((Bounds)(ref bounds)).size; return new Bounds(val3, size); } private Bounds? EncapsulateColliders(Vector3 boundsCenter, Vector3 boundsSize, GameObject netView) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)m_floatcollider)) { return null; } Bounds value = default(Bounds); ((Bounds)(ref value))..ctor(boundsCenter, boundsSize); Collider[] componentsInChildren = netView.GetComponentsInChildren<Collider>(); foreach (Collider val in componentsInChildren) { if (((Component)val).gameObject.layer == PrefabRegistryHelpers.PieceLayer) { Bounds? val2 = TransformColliderGlobalBoundsToLocal(val); if (val2.HasValue) { ((Bounds)(ref value)).Encapsulate(val2.Value); } } } return value; } public static List<Collider> GetCollidersInPiece(GameObject netView) { Piece component = netView.GetComponent<Piece>(); if (Object.op_Implicit((Object)(object)component)) { return ((StaticTarget)component).GetAllColliders(); } Collider[] componentsInChildren = netView.GetComponentsInChildren<Collider>(); List<Collider> list = new List<Collider>(componentsInChildren.Length); Collider[] array = componentsInChildren; foreach (Collider item in array) { list.Add(item); } return list; } public void EncapsulateBounds(GameObject go) { //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) List<Collider> collidersInPiece = GetCollidersInPiece(go); IgnoreShipColliders(collidersInPiece); Door componentInChildren = go.GetComponentInChildren<Door>(); RopeLadderComponent component = go.GetComponent<RopeLadderComponent>(); RopeAnchorComponent component2 = go.GetComponent<RopeAnchorComponent>(); if (Object.op_Implicit((Object)(object)componentInChildren) || Object.op_Implicit((Object)(object)component) || Object.op_Implicit((Object)(object)component2) || ((Object)go).name.StartsWith("MBRaftMast") || ((Object)go).name.StartsWith("MBSail") || ((Object)go).name.StartsWith("MBKarveMast") || ((Object)go).name.StartsWith("MBVikingShipMast") || ((Object)go).name.StartsWith("ValheimVehicles_DrakkalMast")) { return; } if (ValheimRaftPlugin.Instance.EnableExactVehicleBounds.Value || ShipHulls.IsHull(go)) { Bounds? val = EncapsulateColliders(((Bounds)(ref _vehicleBounds)).center, ((Bounds)(ref _vehicleBounds)).size, go); if (val.HasValue) { _vehicleBounds = val.Value; OnShipBoundsChange(); } } else { ((Bounds)(ref _vehicleBounds)).Encapsulate(go.transform.localPosition); } } internal int GetPieceCount() { if (!Object.op_Implicit((Object)(object)m_nview) || m_nview.m_zdo == null) { return m_pieces.Count; } return m_nview.m_zdo.GetInt(MBPieceCount, m_pieces.Count); } } public class VehicleObject { public string itemId; public string prefabName; public float prefabHealth; public float prefabState; } public class BaseVehicleItemStorage { public string vehicleId; public string vehicleName; public Dictionary<string, VehicleObject> registeredItems = new Dictionary<string, VehicleObject>(); public void setItemRegistry(VehicleObject item) { registeredItems.Add(item.itemId, item); } public List<KeyValuePair<string, VehicleObject>> GetVehicleItems() { return registeredItems.ToList(); } } public interface IDrawTargetColliders { BoxCollider collider { get; set; } Color lineColor { get; set; } GameObject parent { get; set; } } public struct DrawTargetColliders : IDrawTargetColliders { public BoxCollider collider { get; set; } public Color lineColor { get; set; } public GameObject parent { get; set; } } public class VehicleDebugHelpers : MonoBehaviour { private struct DrawLineData { public Color color; public Material material; public GameObject parent; public BoxCollider boxCollider; public List<LineRenderer>? lineItems; public float width; public void Deconstruct(out Color o_color, out Material o_material, out GameObject o_parent, out BoxCollider o_boxCollider, out List<LineRenderer>? o_lineItems, out float o_width) { //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) o_color = color; o_material = material; o_parent = parent; o_boxCollider = boxCollider; o_lineItems = lineItems; o_width = width; } } private Dictionary<string, List<LineRenderer>> lines = new Dictionary<string, List<LineRenderer>>(); public bool autoUpdateColliders; private List<IDrawTargetColliders> targetColliders = new List<IDrawTargetColliders>(); public GameObject VehicleObj; public VehicleShip VehicleShipInstance; private Coroutine? _drawColliderCoroutine; private InvokeBinder repeatInvoke; private static readonly Color LineColorDefault = Color.green; private void FixedUpdate() { if (((Behaviour)this).isActiveAndEnabled && autoUpdateColliders) { DrawAllColliders(); } } public void StartRenderAllCollidersLoop() { autoUpdateColliders = !autoUpdateColliders; if (autoUpdateColliders) { return; } foreach (KeyValuePair<string, List<LineRenderer>> line in lines) { if (!lines.TryGetValue(line.Key, out List<LineRenderer> value) || value == null) { continue; } foreach (LineRenderer item in line.Value.ToList().OfType<LineRenderer>()) { Object.Destroy((Object)(object)((Component)item).gameObject); value.Remove(item); } } } private static RaycastHit? RaycastToPiecesUnderPlayerCamera() { //IL_0021: 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_0060: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)Player.m_localPlayer == (Object)null) { return null; } RaycastHit value = default(RaycastHit); if (!Physics.Raycast(((Component)GameCamera.instance).transform.position, ((Component)GameCamera.instance).transform.forward, ref value, 50f, LayerMask.GetMask(new string[1] { "piece" }))) { return null; } return value; } public static VehicleDebugHelpers GetOnboardVehicleDebugHelper() { return GetVehicleController()?.VehicleInstance.Instance.VehicleDebugHelpersInstance; } public static VehicleDebugHelpers? GetOnboardMBRaftDebugHelper() { return GetMBRaftController()?.shipController?.VehicleDebugHelpersInstance; } public static MoveableBaseRootComponent? GetMBRaftController() { //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) RaycastHit? val = RaycastToPiecesUnderPlayerCamera(); if (!val.HasValue) { return null; } RaycastHit valueOrDefault = val.GetValueOrDefault(); return ((Component)((RaycastHit)(ref valueOrDefault)).collider).GetComponentInParent<MoveableBaseRootComponent>(); } public static BaseVehicleController? GetVehicleController() { //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) RaycastHit? val = RaycastToPiecesUnderPlayerCamera(); if (!val.HasValue) { return null; } RaycastHit valueOrDefault = val.GetValueOrDefault(); return ((Component)((RaycastHit)(ref valueOrDefault)).collider).GetComponentInParent<BaseVehicleController>(); } public void FlipShip() { //IL_003a: 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) if (Object.op_Implicit((Object)(object)VehicleShipInstance.m_body)) { VehicleShipInstance.m_body.isKinematic = true; ((Component)this).transform.rotation = Quaternion.Euler(0f, VehicleObj.transform.eulerAngles.y, 0f); VehicleShipInstance.m_body.isKinematic = false; } } public void RenderAllVehicleBoxColliders(BaseVehicleController controller) { } public void MoveShip(Vector3 vector) { //IL_003a: 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_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)VehicleShipInstance.m_body)) { VehicleShipInstance.m_body.isKinematic = true; ((Component)this).transform.rotation = Quaternion.Euler(0f, VehicleObj.transform.eulerAngles.y, 0f); Transform transform = ((Component)this).transform; transform.position += vector; VehicleShipInstance.m_body.isKinematic = false; } } private static void DrawLine(Vector3 start, Vector3 end, int index, DrawLineData data) { //IL_0016: 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_0065: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) DrawLineData drawLineData = data; var (val5, material, val6, val7, list2, num2) = (DrawLineData)(ref drawLineData); if (list2 == null) { throw new ArgumentNullException("lineItems"); } LineRenderer val8; if (index < list2.Count) { val8 = list2[index]; } else { val8 = new GameObject($"{((Object)val7).name}_Line_{index}").AddComponent<LineRenderer>(); ((Component)val8).transform.SetParent(val6.transform); } ((Renderer)val8).material = material; val8.startColor = val5; val8.endColor = val5; val8.startWidth = num2; val8.endWidth = num2; val8.positionCount = 2; val8.useWorldSpace = true; val8.SetPosition(0, start); val8.SetPosition(1, end); if (index < list2.Count) { list2[index] = val8; } else { list2.Add(val8); } } public void AddColliderToRerender(IDrawTargetColliders drawTargetColliders) { targetColliders.Add(drawTargetColliders); } private IEnumerable DrawCollidersCoroutine() { Logger.LogDebug((object)"called DrawCollidersCoroutine"); while (autoUpdateColliders) { Logger.LogDebug((object)"DrawCollidersCoroutine Update"); DrawAllColliders(); yield return null; } yield return null; } private bool DrawAllColliders() { //IL_0024: Unknown result type (might be due to invalid IL or missing references) foreach (IDrawTargetColliders targetCollider in targetColliders) { DrawColliders(targetCollider.collider, targetCollider.parent, targetCollider.lineColor); } return true; } public void DrawColliders(BoxCollider boxCollider, GameObject parent, Color? lineColor) { //IL_0015: 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_001a: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Expected O, but got Unknown //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_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_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) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008a: 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_0091: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: 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_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_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_0100: 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_010c: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_010f: 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_011d: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_0125: 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_012c: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_0135: 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_0138: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0144: 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_014b: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Unknown result type (might be due to invalid IL or missing references) //IL_014e: 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_0157: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0163: 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_0166: Unknown result type (might be due to invalid IL or missing references) //IL_0168: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Unknown result type (might be due to invalid IL or missing references) //IL_0174: Unknown result type (might be due to invalid IL or missing references) //IL_0176: Unknown result type (might be due to invalid IL or missing references) //IL_017b: Unknown result type (might be due to invalid IL or missing references) //IL_017d: 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_0180: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_018e: Unknown result type (might be due to invalid IL or missing references) //IL_0193: Unknown result type (might be due to invalid IL or missing references) //IL_0195: Unknown result type (might be due to invalid IL or missing references) //IL_0196: Unknown result type (might be due to invalid IL or missing references) //IL_0198: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_019f: 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_01a6: Unknown result type (might be due to invalid IL or missing references) //IL_01ab: Unknown result type (might be due to invalid IL or missing references) //IL_01ad: 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_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: Unknown result type (might be due to invalid IL or missing references) //IL_01b7: Unknown result type (might be due to invalid IL or missing references) //IL_01bc: Unknown result type (might be due to invalid IL or missing references) //IL_01be: Unknown result type (might be due to invalid IL or missing references) //IL_01c3: Unknown result type (might be due to invalid IL or missing references) //IL_01c5: Unknown result type (might be due to invalid IL or missing references) //IL_01c6: Unknown result type (might be due to invalid IL or missing references) //IL_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_01d6: Unknown result type (might be due to invalid IL or missing references) //IL_01db: Unknown result type (might be due to invalid IL or missing references) //IL_0216: Unknown result type (might be due to invalid IL or missing references) //IL_0217: Unknown result type (might be due to invalid IL or missing references) //IL_0250: Unknown result type (might be due to invalid IL or missing references) //IL_0252: Unknown result type (might be due to invalid IL or missing references) //IL_0263: Unknown result type (might be due to invalid IL or missing references) //IL_0265: Unknown result type (might be due to invalid IL or missing references) //IL_0276: Unknown result type (might be due to invalid IL or missing references) //IL_0278: Unknown result type (might be due to invalid IL or missing references) //IL_0289: Unknown result type (might be due to invalid IL or missing references) //IL_028b: Unknown result type (might be due to invalid IL or missing references) //IL_029c: Unknown result type (might be due to invalid IL or missing references) //IL_029e: Unknown result type (might be due to invalid IL or missing references) //IL_02af: Unknown result type (might be due to invalid IL or missing references) //IL_02b1: Unknown result type (might be due to invalid IL or missing references) //IL_02c2: Unknown result type (might be due to invalid IL or missing references) //IL_02c4: Unknown result type (might be due to invalid IL or missing references) //IL_02d5: Unknown result type (might be due to invalid IL or missing references) //IL_02d7: Unknown result type (might be due to invalid IL or missing references) //IL_02e8: Unknown result type (might be due to invalid IL or missing references) //IL_02ea: Unknown result type (might be due to invalid IL or missing references) //IL_02fb: Unknown result type (might be due to invalid IL or missing references) //IL_02fd: Unknown result type (might be due to invalid IL or missing references) //IL_030e: Unknown result type (might be due to invalid IL or missing references) //IL_0310: Unknown result type (might be due to invalid IL or missing references) //IL_0321: Unknown result type (might be due to invalid IL or missing references) //IL_0323: Unknown result type (might be due to invalid IL or missing references) Color color = (Color)(((??)lineColor) ?? LineColorDefault); if (!((Object)(object)boxCollider == (Object)null)) { Material material = new Material(LoadValheimVehicleAssets.PieceShader) { color = color }; Vector3 val = ((Component)boxCollider).transform.right; Vector3 normalized = ((Vector3)(ref val)).normalized; val = ((Component)boxCollider).transform.forward; Vector3 normalized2 = ((Vector3)(ref val)).normalized; val = ((Component)boxCollider).transform.up; Vector3 normalized3 = ((Vector3)(ref val)).normalized; Vector3 val2 = ((Component)boxCollider).transform.position + boxCollider.center; Vector3 size = boxCollider.size; size.x *= ((Component)boxCollider).transform.lossyScale.x; size.y *= ((Component)boxCollider).transform.lossyScale.y; size.z *= ((Component)boxCollider).transform.lossyScale.z; Vector3 val3 = size / 2f; Vector3 val4 = normalized3 * val3.y; Vector3 val5 = normalized * val3.x; Vector3 val6 = normalized2 * val3.z; Vector3 val7 = val2 + val4 + val5 + val6; Vector3 val8 = val2 - val4 + val5 + val6; Vector3 val9 = val2 + val4 - val5 + val6; Vector3 end = val2 - val4 - val5 + val6; Vector3 start = val2 + val4 + val5 - val6; Vector3 val10 = val2 - val4 + val5 - val6; Vector3 val11 = val2 + val4 - val5 - val6; Vector3 val12 = val2 - val4 - val5 - val6; if (!lines.TryGetValue(((Object)boxCollider).name, out List<LineRenderer> value)) { value = new List<LineRenderer>(); lines.Add(((Object)boxCollider).name, value); } DrawLineData drawLineData = default(DrawLineData); drawLineData.color = color; drawLineData.boxCollider = boxCollider; drawLineData.parent = parent; drawLineData.material = material; drawLineData.lineItems = value; drawLineData.width = 0.1f; DrawLineData data = drawLineData; int num = 0; DrawLine(val7, val9, num, data); num++; DrawLine(val8, end, num, data); num++; DrawLine(val7, val8, num, data); num++; DrawLine(val9, end, num, data); num++; DrawLine(start, val11, num, data); num++; DrawLine(val10, val12, num, data); num++; DrawLine(start, val10, num, data); num++; DrawLine(val11, val12, num, data); num++; DrawLine(val11, val9, num, data); num++; DrawLine(val12, end, num, data); num++; DrawLine(start, val7, num, data); num++; DrawLine(val10, val8, num, data); lines[((Object)boxCollider).name] = value; } } } public class LandVehicle : MonoBehaviour { } public class SubmergedVehicle { } public class ValheimBaseGameShip : MonoBehaviour { internal float m_sendRudderTime; [Header("Objects")] public GameObject m_sailObject; public GameObject m_mastObject; public GameObject m_rudderObject; public VehicleMovementController m_shipControlls; public Transform? m_controlGuiPos; public BoxCollider m_floatcollider; public float m_waterLevelOffset = 1.5f; public float m_forceDistance = 1f; public float m_force = 0.5f; public float m_damping = 0.05f; public float m_dampingSideway = 0.05f; public float m_dampingForward = 0.01f; public float m_angularDamping = 0.01f; public float m_disableLevel = -0.5f; public float m_sailForceOffset; public float m_sailForceFactor = 0.1f; public float m_stearForceOffset = -10f; public float m_stearForce = 0.5f; public float m_stearVelForceFactor = 0.1f; public float m_backwardForce = 50f; public float m_rudderRotationMax = 30f; public float m_minWaterImpactForce = 2.5f; public float m_minWaterImpactInterval = 2f; public float m_waterImpactDamage = 10f; public float m_upsideDownDmgInterval = 1f; public float m_upsideDownDmg = 20f; public EffectList m_waterImpactEffect = new EffectList(); internal bool m_sailWasInPosition; internal Vector3 m_windChangeVelocity = Vector3.zero; internal Vector3 m_sailForce = Vector3.zero; internal List<Player> m_players = new List<Player>(); internal WaterVolume m_previousCenter; internal WaterVolume m_previousLeft; internal WaterVolume m_previousRight; internal WaterVolume m_previousForward; internal WaterVolume m_previousBack; internal static readonly List<ValheimBaseGameShip> s_currentShips = new List<ValheimBaseGameShip>(); public Rigidbody m_body; internal ZNetView m_nview; internal Cloth m_sailCloth; internal float m_lastDepth = -9999f; internal float m_lastWaterImpactTime; internal float m_upsideDownDmgTimer; internal float m_rudderPaddleTimer; public static List<ValheimBaseGameShip> Instances { get; } = new List<ValheimBaseGameShip>(); public virtual void OnEnable() { Instances.Add(this); } public virtual void OnDisable() { Instances.Remove(this); } internal void Awake() { m_nview = ((Component)this).GetComponent<ZNetView>(); if (!Object.op_Implicit((Object)(object)m_nview)) { Logger.LogError((object)"ValheimBaseShip initialized without NetView, or netview is not available yet (ghost mode?)"); } Transform val = ((Component)this).transform.Find("VehicleShip_FloatCollider"); if ((Object)(object)val != (Object)null) { val.SetParent(((Component)this).transform); BoxCollider val2 = ((Component)val).GetComponentsInChildren<BoxCollider>()?.FirstOrDefault((Func<BoxCollider, bool>)((BoxCollider k) => ((Object)((Component)k).gameObject).name == "VehicleShip_FloatCollider")); if ((Object)(object)val2 != (Object)null) { m_floatcollider = val2; } } if (!Object.op_Implicit((Object)(object)m_floatcollider)) { Logger.LogError((object)"No float collider exists for ship, this is a prefab setup issue."); } WearNTear component = ((Component)this).GetComponent<WearNTear>(); if (Object.op_Implicit((Object)(object)component)) { component.m_onDestroyed = (Action)Delegate.Combine(component.m_onDestroyed, new Action(OnDestroyed)); } if (!Object.op_Implicit((Object)(object)m_body)) { m_body = ((Component)this).GetComponent<Rigidbody>(); Logger.LogError((object)"No rigidbody detected, ship must have a Rigidbody to work"); } m_body.mass = 2000f; m_body.useGravity = true; m_body.maxDepenetrationVelocity = 2f; ZNetView nview = m_nview; if (((nview != null) ? nview.GetZDO() : null) == null) { ((Behaviour)this).enabled = false; } Heightmap.ForceGenerateAll(); m_sailCloth = m_sailObject.GetComponentInChildren<Cloth>(); } public bool CanBeRemoved() { return m_players.Count == 0; } internal void Start() { ((MonoBehaviour)this).InvokeRepeating("UpdateOwner", 2f, 2f); } internal void PrintStats() { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) if (m_players.Count != 0) { Vector3 velocity = m_body.velocity; Logger.LogDebug((object)("Vel:" + ((Vector3)(ref velocity)).magnitude.ToString("0.0"))); } } internal static float GetUpwardsForce(float targetY, float currentY, float maxForce) { float num = targetY - currentY; if (num == 0f) { return 0f; } return Mathf.Clamp(1f / (25f / (num * num)) * ((num > 0f) ? maxForce : (0f - maxForce)), 0f - maxForce, maxForce); } public void UpdateUpsideDmg(float dt) { //IL_0006: 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_004f: Expected O, but got Unknown //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) if (((Component)this).transform.up.y >= 0f) { return; } m_upsideDownDmgTimer += dt; if (!(m_upsideDownDmgTimer <= m_upsideDownDmgInterval)) { m_upsideDownDmgTimer = 0f; IDestructible component = ((Component)this).GetComponent<IDestructible>(); if (component != null) { HitData val = new HitData(); val.m_damage.m_blunt = m_upsideDownDmg; val.m_point = ((Component)this).transform.position; val.m_dir = Vector3.up; component.Damage(val); } } } public Vector3 GetSailForce(float sailSize, float dt) { //IL_0005: 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_0041: 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_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (m