Bonelab mods are targeting MelonLoader version 0.5.7. Newer versions will not work!, so double-check your MelonLoader version if you're having issues.
Decompiled source of PelvisLock v1.0.0
Mods/PelvisLock.dll
Decompiled 6 months agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Resources; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using HarmonyLib; using LabFusion.Data; using LabFusion.Network; using LabFusion.Representation; using LabFusion.SDK.Modules; using LabFusion.Utilities; using MelonLoader; using PelvisLock; using SLZ.Rig; using SLZ.Vehicle; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("PelvisLock")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany(null)] [assembly: AssemblyProduct("PelvisLock")] [assembly: AssemblyCopyright("Created by ")] [assembly: AssemblyTrademark(null)] [assembly: ComVisible(false)] [assembly: AssemblyFileVersion("1.0.0")] [assembly: NeutralResourcesLanguage("en")] [assembly: MelonInfo(typeof(global::PelvisLock.PelvisLock), "PelvisLock", "1.0.0", null, null)] [assembly: ModuleInfo(typeof(PelvisLockModule), "PelvisLockModule", "1.0.0", "Evro", "pelvismodule", true, ConsoleColor.Red)] [assembly: MelonGame(null, null)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("1.0.0.0")] namespace PelvisLock; public static class BuildInfo { public const string Name = "PelvisLock"; public const string Author = null; public const string Company = null; public const string Version = "1.0.0"; public const string DownloadLink = null; } public class PelvisLock : MelonMod { [HarmonyPatch(typeof(UIRig), "Awake")] public static class PhysAwake { public static void Postfix(UIRig __instance) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Expected O, but got Unknown //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: 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_010f: Unknown result type (might be due to invalid IL or missing references) Manager = __instance.manager; GameObject val = new GameObject("PelvisLockSeat" + Random.Range(0, 10000)); seat = val.AddComponent<Seat>(); seat.footLf = new GameObject("FootL").transform; seat.footLf.parent = ((Component)seat).transform; seat.footRt = new GameObject("FootR").transform; seat.footRt.parent = ((Component)seat).transform; seat.spineRom = new Vector4(60f, 180f, 60f, 40f); ((Collider)((Component)seat).gameObject.AddComponent<BoxCollider>()).isTrigger = true; seat.minSeatBounds = new Vector3(0.1f, 0f, 0.1f); seat.maxSeatBounds = new Vector3(5f, 0f, 5f); ((Component)seat).gameObject.AddComponent<Rigidbody>().isKinematic = true; seat.seatRb = ((Component)seat).GetComponent<Rigidbody>(); seat.blockUnseatAction = true; ((Component)seat).gameObject.AddComponent<Atv>().driverSeat = seat; } } [HarmonyPatch(typeof(OpenController), "OnUpdate")] public static class ControllerPress { public static void Postfix(OpenController __instance) { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Invalid comparison between Unknown and I4 if (__instance.GetThumbStickDown() && ((Object)(object)Manager.activeSeat == (Object)(object)seat || (Object)(object)Manager.activeSeat == (Object)null) && (int)((BaseController)__instance).handedness == 2) { if (!Enabled) { LockPelvis(); } else { Unlock(); } } } } public static Seat seat; public static RigManager Manager; public static bool Enabled; public override void OnInitializeMelon() { MelonLogger.Msg("Loading Pelvis Module"); ModuleHandler.LoadModule(Assembly.GetExecutingAssembly()); } public static void LockPelvis() { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: 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_007b: 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) ((Component)seat).transform.position = ((Rig)Manager.artOutputRig).m_pelvis.position + new Vector3(0f, -0.2f, 0f); ((Component)seat).transform.rotation = ((Rig)Manager.artOutputRig).m_pelvis.rotation; seat.footLf.position = Manager.artOutputRig.artToeLf.position; seat.footRt.position = Manager.artOutputRig.artToeRt.position; seat.Register(Manager); Enabled = true; } public static void Unlock() { seat.DeRegister(); Enabled = false; } public override void OnUpdate() { //IL_003f: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)Manager != (Object)null && (Object)(object)Manager.activeSeat == (Object)null) { ((Component)seat).transform.rotation = ((Rig)Manager.artOutputRig).m_pelvis.rotation; } } } internal class PelvisLockData : IFusionSerializable, IDisposable { public byte playerShortId; public bool isUnseat; public string seatName; public void Deserialize(FusionReader reader) { playerShortId = reader.ReadByte(); isUnseat = reader.ReadBoolean(); seatName = reader.ReadString(); } public void Dispose() { GC.SuppressFinalize(this); } public void Serialize(FusionWriter writer) { writer.Write(playerShortId); writer.Write(isUnseat); writer.Write(seatName); } public static PelvisLockData Create(byte shortId, bool isUnsit, string name) { return new PelvisLockData { playerShortId = shortId, isUnseat = isUnsit, seatName = name }; } } public class PelvisLockMessage : ModuleMessageHandler { public override void HandleMessage(byte[] bytes, bool isServerHandled = false) { FusionReader val = FusionReader.Create(bytes); try { using PelvisLockData pelvisLockData = val.ReadFusionSerializable<PelvisLockData>(); if (NetworkInfo.IsServer && isServerHandled) { FusionMessage val2 = FusionMessage.ModuleCreate<PelvisLockMessage>(bytes); try { MessageSender.BroadcastMessageExcept(pelvisLockData.playerShortId, (NetworkChannel)0, val2, true); } finally { ((IDisposable)val2)?.Dispose(); } } PlayerId playerId = PlayerIdManager.GetPlayerId(pelvisLockData.playerShortId); PlayerRep key = default(PlayerRep); if (PlayerRepManager.TryGetPlayerRep(PlayerId.op_Implicit(playerId), ref key) && RepPelvisLock.plManagers.ContainsKey(key)) { RepPelvisLock repPelvisLock = RepPelvisLock.plManagers[key]; if (pelvisLockData.isUnseat) { repPelvisLock.Unlock(); } else { repPelvisLock.LockPlayerRep(pelvisLockData.seatName); } } } finally { ((IDisposable)val)?.Dispose(); } } } public class PelvisLockModule : Module { public override void OnModuleLoaded() { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Expected O, but got Unknown //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Expected O, but got Unknown MelonLogger.Msg("Test"); MultiplayerHooking.OnPlayerRepCreated += new RigManagerEvent(OnPlayerRepCreated); MultiplayerHooking.OnUpdate += new UpdateEvent(OnUpdate); } private void OnUpdate() { foreach (KeyValuePair<PlayerRep, RepPelvisLock> plManager in RepPelvisLock.plManagers) { plManager.Value.Update(); } } private void OnPlayerRepCreated(RigManager rig) { PlayerRep rep = default(PlayerRep); if (PlayerRepManager.TryGetPlayerRep(rig, ref rep)) { new RepPelvisLock(rep, rig); } } } internal class PelvisLockPatches { [HarmonyPatch(typeof(PelvisLock), "LockPelvis")] public static class LockPatch { public static void Postfix() { if (!NetworkInfo.HasServer) { return; } FusionWriter val = FusionWriter.Create(); try { using PelvisLockData pelvisLockData = PelvisLockData.Create(PlayerIdManager.LocalId.SmallId, isUnsit: false, ((Object)((Component)PelvisLock.seat).gameObject).name); val.Write<PelvisLockData>(pelvisLockData); FusionMessage val2 = FusionMessage.ModuleCreate<PelvisLockMessage>(val); try { MessageSender.SendToServer((NetworkChannel)0, val2); } finally { ((IDisposable)val2)?.Dispose(); } } finally { ((IDisposable)val)?.Dispose(); } } } [HarmonyPatch(typeof(PelvisLock), "Unlock")] public static class UnlockPatch { public static void Prefix() { if (!NetworkInfo.HasServer) { return; } FusionWriter val = FusionWriter.Create(); try { using PelvisLockData pelvisLockData = PelvisLockData.Create(PlayerIdManager.LocalId.SmallId, isUnsit: true, ((Object)((Component)PelvisLock.seat).gameObject).name); val.Write<PelvisLockData>(pelvisLockData); FusionMessage val2 = FusionMessage.ModuleCreate<PelvisLockMessage>(val); try { MessageSender.SendToServer((NetworkChannel)0, val2); } finally { ((IDisposable)val2)?.Dispose(); } } finally { ((IDisposable)val)?.Dispose(); } } } } internal class RepPelvisLock { public static Dictionary<PlayerRep, RepPelvisLock> plManagers = new Dictionary<PlayerRep, RepPelvisLock>(); private RigManager Manager; private Seat seat; public RepPelvisLock(PlayerRep rep, RigManager rig) { //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Expected O, but got Unknown //IL_0073: 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_00f0: 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_0127: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) if (plManagers.ContainsKey(rep)) { plManagers.Remove(rep); } plManagers.Add(rep, this); Manager = rig; GameObject val = new GameObject("PelvisLockSeat" + rep.PlayerId.SmallId); seat = val.AddComponent<Seat>(); seat.footLf = new GameObject("FootL").transform; seat.footLf.parent = ((Component)seat).transform; seat.footRt = new GameObject("FootR").transform; seat.footRt.parent = ((Component)seat).transform; seat.spineRom = new Vector4(60f, 180f, 60f, 40f); ((Collider)((Component)seat).gameObject.AddComponent<BoxCollider>()).isTrigger = true; ((Component)seat).GetComponent<BoxCollider>().center = Vector3.one * 5000f; seat.minSeatBounds = new Vector3(0.1f, 0f, 0.1f); seat.maxSeatBounds = new Vector3(5f, 0f, 5f); ((Component)seat).gameObject.AddComponent<Rigidbody>().isKinematic = true; seat.seatRb = ((Component)seat).GetComponent<Rigidbody>(); seat.blockUnseatAction = true; } public void LockPlayerRep(string name) { //IL_002e: 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) //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_0093: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) ((Object)((Component)seat).gameObject).name = name; ((Component)seat).transform.rotation = ((Rig)Manager.artOutputRig).m_pelvis.rotation; ((Component)seat).transform.position = ((Rig)Manager.artOutputRig).m_pelvis.position + new Vector3(0f, -0.2f, 0f); seat.footLf.position = Manager.artOutputRig.artToeLf.position; seat.footRt.position = Manager.artOutputRig.artToeRt.position; seat.Register(Manager); } public void Unlock() { seat.DeRegister(); } public void Update() { //IL_0043: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)Manager != (Object)null && (Object)(object)Manager.activeSeat == (Object)null) { ((Component)seat).transform.rotation = ((Rig)Manager.artOutputRig).m_pelvis.rotation; } } }