Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of RaftNpsBridge v0.2.2
RaftNpsBridge.dll
Decompiled an hour agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using RaftNpsBridge.Patches; using UnityEngine; using ValheimVehicles.Components; using ValheimVehicles.Controllers; using ValheimVehicles.Enums; using ValheimVehicles.Helpers; using ValheimVehicles.Serialization; using ValheimVehicles.Shared.Constants; using ValheimVehicles.SharedScripts; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("RaftNpsBridge")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.2.2.0")] [assembly: AssemblyInformationalVersion("0.2.2+a9dd2f7c35082a725aa3dd73c05825f85055333b")] [assembly: AssemblyProduct("RaftNpsBridge")] [assembly: AssemblyTitle("RaftNpsBridge")] [assembly: AssemblyVersion("0.2.2.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [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] [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] [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 RaftNpsBridge { [BepInPlugin("local.RaftNpsBridge", "RaftNpsBridge", "0.2.2")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { public const string Guid = "local.RaftNpsBridge"; public const string Name = "RaftNpsBridge"; public const string Version = "0.2.2"; public const string RaftGuid = "zolantris.ValheimRAFT"; public const string NpsGuid = "MidnightsFX.NetworkPerformanceSystem"; internal static ManualLogSource Log; private void Awake() { //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; ConfigEntry<bool> val = ((BaseUnityPlugin)this).Config.Bind<bool>("ValheimRAFT fixes", "VehicleOwnerUsesConnectionId", true, "When a player takes the wheel, give the vehicle, its pieces and its ram to that player's connection id. ValheimRAFT 5.1.3 uses the character id, which no connection matches, so the server hands the vehicle to whichever nearby player it checks first."); ConfigEntry<bool> val2 = ((BaseUnityPlugin)this).Config.Bind<bool>("ValheimRAFT fixes", "ServerSafeControlResponse", true, "On a dedicated server, run the wheel handoff without the player message that throws a NullReferenceException there (ValheimRAFT issue 363)."); ConfigEntry<bool> val3 = ((BaseUnityPlugin)this).Config.Bind<bool>("ValheimRAFT fixes", "WaitForPiecesAfterLoad", true, "Keep a freshly loaded vehicle frozen until its pieces stop arriving (2s quiet) and its hull has been built from all of them (at most 30s), then recalculate its centre of mass. While it waits, the hull is built from the pieces instead of loading the one stored with the vehicle."); ConfigEntry<bool> val4 = ((BaseUnityPlugin)this).Config.Bind<bool>("ValheimRAFT fixes", "CenterOfMassAfterHullRebuild", true, "Recalculate the centre of mass whenever the vehicle hull is rebuilt, instead of only on ValheimRAFT's 30s timer."); ConfigEntry<bool> val5 = ((BaseUnityPlugin)this).Config.Bind<bool>("ValheimRAFT fixes", "IgnoreChestCallbacksToRemovedAmmoTracker", true, "Skip chest change callbacks that reach an ammo tracker which no longer exists. Without this the callback throws inside the chest's inventory load."); ConfigEntry<bool> val6 = ((BaseUnityPlugin)this).Config.Bind<bool>("ValheimRAFT fixes", "RefuseOutdatedStoredHull", true, "Build a loading vehicle's hull from its pieces instead of loading the hull stored with it, and afterwards refuse a stored hull that falls more than 1 m short of the hull built from the pieces. ValheimRAFT cannot save hulls with more than 255 triangles per part, so a vehicle that grew past that keeps an old, smaller hull and loads it when it loads after a portal and when someone takes the wheel: it jumps vertically, parts of it sink into the ground and the player at the wheel is thrown off. Also logs how the stored hull compares when the vehicle loads."); ConfigEntry<bool> val7 = ((BaseUnityPlugin)this).Config.Bind<bool>("NetworkPerformanceSystem", "LeaveRaftVehiclesAlone", true, "Stop NetworkPerformanceSystem moving the ownership of ValheimRAFT vehicles and their pieces. ValheimRAFT hands them to the player at the wheel itself. Only has an effect where NetworkPerformanceSystem is installed (it arbitrates on the server)."); Harmony harmony = new Harmony("local.RaftNpsBridge"); Apply(harmony, typeof(VehicleOwnerPatches), val.Value); Apply(harmony, typeof(ServerControlResponsePatch), val2.Value); Apply(harmony, typeof(LoadSettlePatches), val3.Value); Apply(harmony, typeof(CenterOfMassPatch), val4.Value); Apply(harmony, typeof(AmmoControllerPatch), val5.Value); Apply(harmony, typeof(StoredHullPatches), val6.Value); if (!Chainloader.PluginInfos.ContainsKey("MidnightsFX.NetworkPerformanceSystem")) { Log.LogInfo((object)"NetworkPerformanceSystem not installed: its ownership patch is not needed here."); } else if (!val7.Value) { Log.LogInfo((object)"NpsOwnershipPatch: disabled in config."); } else { NpsOwnershipPatch.Apply(harmony); } } private static void Apply(Harmony harmony, Type patchClass, bool enabled) { if (!enabled) { Log.LogInfo((object)(patchClass.Name + ": disabled in config.")); return; } try { harmony.CreateClassProcessor(patchClass).Patch(); Log.LogInfo((object)(patchClass.Name + ": applied.")); } catch (Exception ex) { Log.LogError((object)(patchClass.Name + ": NOT applied, the ValheimRAFT method it patches may have changed. " + ex.Message)); } } } internal static class BuildInfo { public const string Version = "0.2.2"; } } namespace RaftNpsBridge.Patches { [HarmonyPatch(typeof(AmmoController), "OnContainerChanged")] internal static class AmmoControllerPatch { private static bool Prefix(AmmoController __instance) { return (Object)(object)__instance != (Object)null; } } [HarmonyPatch] internal static class LoadSettlePatches { private sealed class PieceState { public float LastPieceTime; public int PieceRevision; public int BuildRevision = -1; public int LastHullRevision = -1; public int RebuildRequestedForRevision = -1; public float RebuildRequestedTime = -1f; } private sealed class SettleState { public float StartTime = -1f; public bool HasSettled; public float ReleaseTime = -1f; public float PhysicsStartTime = -1f; public float TopSpeed; public bool HasLoggedTopSpeed; } private const float QuietSeconds = 2f; private const float MaxWaitSeconds = 30f; private const float SpeedWatchSeconds = 5f; private const float RebuildRetrySeconds = 3f; private static readonly ConditionalWeakTable<VehiclePiecesController, PieceState> PieceStates = new ConditionalWeakTable<VehiclePiecesController, PieceState>(); private static readonly ConditionalWeakTable<VehicleMovementController, SettleState> SettleStates = new ConditionalWeakTable<VehicleMovementController, SettleState>(); private static VehiclePiecesController? _buildingFromPieces; [HarmonyPatch(typeof(VehiclePiecesController), "IncrementPieceRevision")] [HarmonyPostfix] private static void IncrementPieceRevision_Postfix(VehiclePiecesController __instance) { PieceState orCreateValue = PieceStates.GetOrCreateValue(__instance); orCreateValue.LastPieceTime = Time.time; orCreateValue.PieceRevision++; } [HarmonyPatch(typeof(BasePiecesController), "RebuildBounds")] [HarmonyPrefix] private static void RebuildBounds_Prefix(BasePiecesController __instance) { VehiclePiecesController val = (VehiclePiecesController)(object)((__instance is VehiclePiecesController) ? __instance : null); if (val != null) { PieceState orCreateValue = PieceStates.GetOrCreateValue(val); orCreateValue.BuildRevision = orCreateValue.PieceRevision; _buildingFromPieces = val; } } [HarmonyPatch(typeof(BasePiecesController), "RebuildBounds")] [HarmonyFinalizer] private static void RebuildBounds_Finalizer() { _buildingFromPieces = null; } [HarmonyPatch(typeof(VehiclePiecesController), "OnConvexHullGenerated")] [HarmonyPostfix] private static void OnConvexHullGenerated_Postfix(VehiclePiecesController __instance, bool hasSucceeded) { if (hasSucceeded && !((Object)(object)_buildingFromPieces != (Object)(object)__instance)) { PieceState orCreateValue = PieceStates.GetOrCreateValue(__instance); orCreateValue.LastHullRevision = orCreateValue.BuildRevision; } } [HarmonyPatch(typeof(VehicleManager), "IsConvexHullInitialized")] [HarmonyPostfix] private static void IsConvexHullInitialized_Postfix(VehicleManager __instance, ref bool __result) { if (__result) { VehicleMovementController movementController = __instance.MovementController; if (!((Object)(object)movementController == (Object)null) && (!SettleStates.TryGetValue(movementController, out SettleState value) || !value.HasSettled)) { __result = false; } } } [HarmonyPatch(typeof(VehicleMovementController), "GuardedFixedUpdate")] [HarmonyPrefix] private static bool GuardedFixedUpdate_Prefix(VehicleMovementController __instance) { //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0065: 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_006a: Invalid comparison between Unknown and I4 //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Invalid comparison between Unknown and I4 VehiclePiecesController piecesController = __instance.PiecesController; if ((Object)(object)piecesController == (Object)null || !((BasePiecesController)piecesController).IsInitialPieceActivationComplete) { return true; } SettleState orCreateValue = SettleStates.GetOrCreateValue(__instance); if (orCreateValue.HasSettled) { WatchTopSpeed(__instance, orCreateValue); return true; } float time = Time.time; if (orCreateValue.StartTime < 0f) { orCreateValue.StartTime = time; } PieceState orCreateValue2 = PieceStates.GetOrCreateValue(piecesController); PendingPieceStateEnum pendingPiecesState = piecesController.PendingPiecesState; bool flag = pendingPiecesState - 1 <= 1; bool flag2 = flag; bool flag3 = time - orCreateValue2.LastPieceTime >= 2f; bool flag4 = (int)((BasePiecesController)piecesController).selectedHullGenerationMode != 0 || orCreateValue2.LastHullRevision >= orCreateValue2.PieceRevision; bool flag5 = time - orCreateValue.StartTime >= 30f; if (!flag5 && (flag2 || !flag3 || !flag4)) { if (!flag2 && flag3 && !flag4 && (orCreateValue2.RebuildRequestedForRevision != orCreateValue2.PieceRevision || time - orCreateValue2.RebuildRequestedTime >= 3f)) { orCreateValue2.RebuildRequestedForRevision = orCreateValue2.PieceRevision; orCreateValue2.RebuildRequestedTime = time; try { piecesController.ForceRebuildBounds(); } catch (Exception ex) { ManualLogSource log = Plugin.Log; VehicleManager manager = __instance.Manager; log.LogWarning((object)$"Vehicle {((manager != null) ? new int?(manager.PersistentZdoId) : ((int?)null))}: could not request a hull rebuild. {ex.Message}"); } } if ((Object)(object)((ValheimBaseGameShip)__instance).m_body != (Object)null) { ((ValheimBaseGameShip)__instance).m_body.isKinematic = true; } return false; } if (flag5) { string arg = ((!flag4 && flag3 && !flag2) ? "a hull built from all its pieces" : "its pieces"); ManualLogSource log2 = Plugin.Log; VehicleManager manager2 = __instance.Manager; log2.LogWarning((object)$"Vehicle {((manager2 != null) ? new int?(manager2.PersistentZdoId) : ((int?)null))} was still waiting for {arg} after {30f}s. Starting physics anyway."); } else { ManualLogSource log3 = Plugin.Log; VehicleManager manager3 = __instance.Manager; log3.LogInfo((object)$"Vehicle {((manager3 != null) ? new int?(manager3.PersistentZdoId) : ((int?)null))}: pieces stopped arriving and the hull was built from all of them after {time - orCreateValue.StartTime:F1}s, releasing it to ValheimRAFT's physics."); } orCreateValue.HasSettled = true; orCreateValue.ReleaseTime = time; if ((Object)(object)((ValheimBaseGameShip)__instance).m_body != (Object)null) { __instance.UpdateCenterOfMass(); } return true; } private static void WatchTopSpeed(VehicleMovementController movement, SettleState state) { //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) if (state.HasLoggedTopSpeed || state.ReleaseTime < 0f) { return; } Rigidbody body = ((ValheimBaseGameShip)movement).m_body; if ((Object)(object)body == (Object)null) { return; } if (state.PhysicsStartTime < 0f) { if (body.isKinematic) { return; } state.PhysicsStartTime = Time.time; } if (!body.isKinematic) { float topSpeed = state.TopSpeed; Vector3 linearVelocity = body.linearVelocity; state.TopSpeed = Mathf.Max(topSpeed, ((Vector3)(ref linearVelocity)).magnitude); } if (!(Time.time - state.PhysicsStartTime < 5f)) { state.HasLoggedTopSpeed = true; VehicleManager manager = movement.Manager; string text = $"Vehicle {((manager != null) ? new int?(manager.PersistentZdoId) : ((int?)null))}: top speed in the first {5f:F0}s of physics was {state.TopSpeed:F1} m/s."; if (state.TopSpeed > 3f) { Plugin.Log.LogWarning((object)text); } else { Plugin.Log.LogInfo((object)text); } } } } [HarmonyPatch(typeof(VehiclePiecesController), "OnConvexHullGenerated")] internal static class CenterOfMassPatch { private static void Postfix(VehiclePiecesController __instance, bool hasSucceeded) { if (hasSucceeded) { VehicleMovementController movementController = __instance.MovementController; if ((Object)(object)movementController != (Object)null && (Object)(object)((ValheimBaseGameShip)movementController).m_body != (Object)null) { movementController.UpdateCenterOfMass(); } } } } internal static class NpsOwnershipPatch { private const string TargetMethod = "NetworkPerformanceSystem.Runtime.OwnershipPolicy:IsDirectlyControlled"; private static readonly Dictionary<int, bool> IsVehiclePrefabByHash = new Dictionary<int, bool>(); public static void Apply(Harmony harmony) { //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Expected O, but got Unknown MethodInfo methodInfo = AccessTools.Method("NetworkPerformanceSystem.Runtime.OwnershipPolicy:IsDirectlyControlled", new Type[1] { typeof(ZDO) }, (Type[])null); if (methodInfo == null || methodInfo.ReturnType != typeof(bool)) { Plugin.Log.LogWarning((object)"NpsOwnershipPatch: NOT applied, NetworkPerformanceSystem.Runtime.OwnershipPolicy:IsDirectlyControlled(ZDO) was not found. NetworkPerformanceSystem may have changed; ValheimRAFT vehicles are not protected from its ownership moves."); return; } try { harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(NpsOwnershipPatch), "Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); Plugin.Log.LogInfo((object)"NpsOwnershipPatch: applied."); } catch (Exception ex) { Plugin.Log.LogError((object)("NpsOwnershipPatch: NOT applied. " + ex.Message)); } } private static void Postfix(ZDO __0, ref bool __result) { if (!__result && __0 != null && (IsVehiclePrefab(__0.GetPrefab()) || __0.GetInt(VehicleZdoVars.MBParentId, 0) != 0)) { __result = true; } } private static bool IsVehiclePrefab(int prefabHash) { if (IsVehiclePrefabByHash.TryGetValue(prefabHash, out var value)) { return value; } if ((Object)(object)ZNetScene.instance == (Object)null) { return false; } GameObject prefab = ZNetScene.instance.GetPrefab(prefabHash); if ((Object)(object)prefab == (Object)null) { return false; } bool flag = PrefabNames.IsVehicle(((Object)prefab).name) || ((Object)prefab).name.StartsWith(PrefabNames.AirVehicle); IsVehiclePrefabByHash[prefabHash] = flag; return flag; } } [HarmonyPatch] internal static class StoredHullPatches { private sealed class HullReference { public Bounds PieceBuiltBounds; public bool HasPieceBuiltBounds; public string? LastLoggedComparison; } private const float ToleranceMetres = 1f; private static readonly ConditionalWeakTable<VehiclePiecesController, HullReference> References = new ConditionalWeakTable<VehiclePiecesController, HullReference>(); private static bool _isApplyingStoredHull; [HarmonyPatch(typeof(BasePiecesController), "RebuildBoundsFromData")] [HarmonyPrefix] private static bool RebuildBoundsFromData_Prefix(BasePiecesController __instance, List<ColliderData> hulls) { //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_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_0086: 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) _isApplyingStoredHull = true; VehiclePiecesController val = (VehiclePiecesController)(object)((__instance is VehiclePiecesController) ? __instance : null); if (val == null) { return true; } if (!References.TryGetValue(val, out HullReference value) || !value.HasPieceBuiltBounds) { Plugin.Log.LogInfo((object)$"Vehicle {val.PersistentZdoId}: not applying the stored hull before this game has built one from the pieces."); _isApplyingStoredHull = false; return false; } if (!TryGetBounds(hulls, out var bounds)) { return true; } float num = Shortfall(value.PieceBuiltBounds, bounds); if (num <= 1f) { Plugin.Log.LogInfo((object)$"Vehicle {val.PersistentZdoId}: applying the stored hull ({Describe(bounds)}); it covers the hull built from the pieces ({Describe(value.PieceBuiltBounds)})."); return true; } Plugin.Log.LogWarning((object)$"Vehicle {val.PersistentZdoId}: refused an out-of-date stored hull. It falls short of the vehicle by {num:F1} m (stored {Describe(bounds)}, built from the pieces {Describe(value.PieceBuiltBounds)}). Keeping the current hull."); _isApplyingStoredHull = false; return false; } [HarmonyPatch(typeof(VehicleManager), "IsConvexHullInitialized")] [HarmonyPostfix] private static void IsConvexHullInitialized_Postfix(VehicleManager __instance, ref bool __result) { if (__result) { VehiclePiecesController piecesController = __instance.PiecesController; if (!((Object)(object)piecesController == (Object)null) && (!References.TryGetValue(piecesController, out HullReference value) || !value.HasPieceBuiltBounds)) { __result = false; } } } [HarmonyPatch(typeof(BasePiecesController), "RebuildBoundsFromData")] [HarmonyFinalizer] private static void RebuildBoundsFromData_Finalizer() { _isApplyingStoredHull = false; } [HarmonyPatch(typeof(VehiclePiecesController), "OnConvexHullGenerated")] [HarmonyPostfix] private static void OnConvexHullGenerated_Postfix(VehiclePiecesController __instance, bool hasSucceeded) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) if (hasSucceeded && !_isApplyingStoredHull && TryGetBounds(__instance, out var bounds)) { HullReference orCreateValue = References.GetOrCreateValue(__instance); orCreateValue.PieceBuiltBounds = bounds; orCreateValue.HasPieceBuiltBounds = true; LogStoredHullComparison(__instance, orCreateValue); } } private static void LogStoredHullComparison(VehiclePiecesController pieces, HullReference reference) { //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) bool flag = false; byte[] hullData = pieces.GetHullData(); string comparison; if (hullData == null || hullData.Length == 0) { comparison = "no hull is stored with the vehicle"; } else { List<ColliderData> hulls; try { hulls = ConvexHullDataSerializer.Deserialize(hullData); } catch (Exception ex) { comparison = "the stored hull cannot be read (" + ex.Message + ")"; LogOnChange(pieces, reference, comparison, flag); return; } if (!TryGetBounds(hulls, out var bounds)) { comparison = "the stored hull has no solid parts"; } else { float num = Shortfall(reference.PieceBuiltBounds, bounds); ZDO zdo = pieces.m_zdo; int num2 = ((zdo != null) ? zdo.GetInt(VehicleZdoVars.VehicleConvexHullDataVersionHash, 0) : 0); flag = num > 1f; comparison = (flag ? $"the stored hull (revision {num2}, {Describe(bounds)}) is out of date: it falls short of the vehicle by {num:F1} m" : $"the stored hull (revision {num2}, {Describe(bounds)}) covers the vehicle"); } } LogOnChange(pieces, reference, comparison, flag); } private static void LogOnChange(VehiclePiecesController pieces, HullReference reference, string comparison, bool isWarning) { //IL_0032: Unknown result type (might be due to invalid IL or missing references) if (!(comparison == reference.LastLoggedComparison)) { reference.LastLoggedComparison = comparison; string text = $"Vehicle {pieces.PersistentZdoId}: hull built from the pieces ({Describe(reference.PieceBuiltBounds)}, {CountTriangles(pieces)} triangles); {comparison}."; if (isWarning) { Plugin.Log.LogWarning((object)text); } else { Plugin.Log.LogInfo((object)text); } } } private static float Shortfall(Bounds reference, Bounds stored) { //IL_0002: 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_0013: 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_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_0027: 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_0036: 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_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) Vector3 val = ((Bounds)(ref stored)).min - ((Bounds)(ref reference)).min; Vector3 val2 = ((Bounds)(ref reference)).max - ((Bounds)(ref stored)).max; return Mathf.Max(new float[3] { 0f, Mathf.Max(val.x, Mathf.Max(val.y, val.z)), Mathf.Max(val2.x, Mathf.Max(val2.y, val2.z)) }); } private static bool TryGetBounds(List<ColliderData>? hulls, out Bounds bounds) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) bounds = default(Bounds); bool hasPoint = false; if (hulls == null) { return false; } foreach (ColliderData hull in hulls) { if (hull != null && !hull.IsTrigger && hull.Vertices != null) { Vector3[] vertices = hull.Vertices; foreach (Vector3 point in vertices) { Encapsulate(ref bounds, ref hasPoint, point); } } } return hasPoint; } private static bool TryGetBounds(VehiclePiecesController pieces, out Bounds bounds) { //IL_0001: 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_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) bounds = default(Bounds); bool hasPoint = false; List<MeshCollider> list = (((Object)(object)pieces.convexHullComponent != (Object)null) ? ((ConvexHullAPI)pieces.convexHullComponent).convexHullMeshColliders : null); if (list == null) { return false; } Transform transform = ((Component)pieces).transform; foreach (MeshCollider item in list) { if (!((Object)(object)item == (Object)null) && !((Collider)item).isTrigger && !((Object)(object)item.sharedMesh == (Object)null)) { Transform transform2 = ((Component)item).transform; Vector3[] vertices = item.sharedMesh.vertices; foreach (Vector3 val in vertices) { Encapsulate(ref bounds, ref hasPoint, transform.InverseTransformPoint(transform2.TransformPoint(val))); } } } return hasPoint; } private static void Encapsulate(ref Bounds bounds, ref bool hasPoint, Vector3 point) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) if (!hasPoint) { bounds = new Bounds(point, Vector3.zero); hasPoint = true; } else { ((Bounds)(ref bounds)).Encapsulate(point); } } private static int CountTriangles(VehiclePiecesController pieces) { int num = 0; List<MeshCollider> list = (((Object)(object)pieces.convexHullComponent != (Object)null) ? ((ConvexHullAPI)pieces.convexHullComponent).convexHullMeshColliders : null); if (list == null) { return 0; } foreach (MeshCollider item in list) { if (!((Object)(object)item == (Object)null) && !((Collider)item).isTrigger && !((Object)(object)item.sharedMesh == (Object)null)) { num += item.sharedMesh.triangles.Length / 3; } } return num; } private static string Describe(Bounds bounds) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0031: 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_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) Vector3 size = ((Bounds)(ref bounds)).size; return $"{size.x:F1} x {size.y:F1} x {size.z:F1} m centred at ({((Bounds)(ref bounds)).center.x:F1}, {((Bounds)(ref bounds)).center.y:F1}, {((Bounds)(ref bounds)).center.z:F1})"; } } [HarmonyPatch(typeof(VehicleMovementController), "OnControlsHandOff")] internal static class VehicleOwnerPatches { private static void Postfix(VehicleMovementController __instance, Player? targetPlayer) { if ((Object)(object)targetPlayer == (Object)null || !Object.op_Implicit((Object)(object)__instance.Manager) || (Object)(object)__instance.PiecesController == (Object)null || (Object)(object)__instance.m_nview == (Object)null || __instance.m_nview.GetZDO() == null) { return; } long owner = ((Character)targetPlayer).GetOwner(); if (owner != 0L) { __instance.PiecesController.ClaimOwnershipAllPieces(owner); VehicleRamAoe vehicleRam = __instance.vehicleRam; if ((Object)(object)vehicleRam != (Object)null && (Object)(object)((ValheimAoe)vehicleRam).m_nview != (Object)null && ((ValheimAoe)vehicleRam).m_nview.GetZDO() != null) { ((ValheimAoe)vehicleRam).m_nview.GetZDO().SetOwner(owner); } } } } [HarmonyPatch(typeof(VehicleMovementController), "RPC_RequestResponse")] internal static class ServerControlResponsePatch { private static bool Prefix(VehicleMovementController __instance, bool granted, long targetPlayerId, long previousPlayerId) { if ((Object)(object)Player.m_localPlayer != (Object)null) { return true; } __instance.CancelDebounceTakeoverControls(); if (!Object.op_Implicit((Object)(object)__instance.Manager)) { return false; } if (granted) { __instance.OnControlsHandOff(Player.GetPlayer(targetPlayerId), Player.GetPlayer(previousPlayerId)); } return false; } } }