Decompiled source of CreFlipMods v1.0.2
plugins/FlipMods-BetterStamina/BetterStamina.dll
Decompiled 10 months agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Serialization.Formatters.Binary; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BetterStamina.Config; using GameNetcodeStuff; using HarmonyLib; using Unity.Collections; using Unity.Netcode; 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("BetterStamina")] [assembly: AssemblyDescription("Mod made by flipf17")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("BetterStamina")] [assembly: AssemblyCopyright("Copyright © 2023")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("1c42022e-b386-4342-baf0-67de1b7529e2")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("1.0.0.0")] namespace BetterStamina { [BepInPlugin("FlipMods.BetterStamina", "BetterStamina", "1.3.2")] public class Plugin : BaseUnityPlugin { private Harmony _harmony; public static Plugin instance; private void Awake() { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Expected O, but got Unknown instance = this; ConfigSettings.BindConfigSettings(); _harmony = new Harmony("BetterStamina"); _harmony.PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"BetterStamina loaded"); } public static void Log(string message) { ((BaseUnityPlugin)instance).Logger.LogInfo((object)message); } public static void LogError(string message) { ((BaseUnityPlugin)instance).Logger.LogError((object)message); } } public static class PluginInfo { public const string PLUGIN_GUID = "FlipMods.BetterStamina"; public const string PLUGIN_NAME = "BetterStamina"; public const string PLUGIN_VERSION = "1.3.2"; } } namespace BetterStamina.Patches { [HarmonyPatch] public class PlayerPatcher { private static float currentSprintMeter; [HarmonyPatch(typeof(PlayerControllerB), "Update")] [HarmonyPrefix] public static void UpdateStaminaPrefix(PlayerControllerB __instance) { if (((NetworkBehaviour)__instance).IsOwner && __instance.isPlayerControlled) { currentSprintMeter = __instance.sprintMeter; } } [HarmonyPatch(typeof(PlayerControllerB), "Update")] [HarmonyPostfix] public static void UpdateStaminaPostfix(PlayerControllerB __instance) { if (((NetworkBehaviour)__instance).IsOwner && __instance.isPlayerControlled) { float num = __instance.sprintMeter - currentSprintMeter; if (num < 0f) { __instance.sprintMeter = Mathf.Max(currentSprintMeter + num * ConfigSync.instance.staminaConsumptionMultiplier, 0f); } else if (num > 0f) { __instance.sprintMeter = Mathf.Min(currentSprintMeter + num * ConfigSync.instance.staminaRegenMultiplier, 1f); } } } [HarmonyPatch(typeof(PlayerControllerB), "LateUpdate")] [HarmonyPrefix] public static void LateUpdatePrefix(PlayerControllerB __instance) { if (((NetworkBehaviour)__instance).IsOwner && __instance.isPlayerControlled) { currentSprintMeter = __instance.sprintMeter; } } [HarmonyPatch(typeof(PlayerControllerB), "LateUpdate")] [HarmonyPostfix] public static void LateUpdateStaminaPostfix(PlayerControllerB __instance) { if (((NetworkBehaviour)__instance).IsOwner && __instance.isPlayerControlled) { float num = __instance.sprintMeter - currentSprintMeter; if (num < 0f) { __instance.sprintMeter = Mathf.Max(currentSprintMeter + num * ConfigSync.instance.staminaConsumptionMultiplier, 0f); } else if (num > 0f) { __instance.sprintMeter = Mathf.Min(currentSprintMeter + num * ConfigSync.instance.staminaRegenMultiplier, 1f); } } } [HarmonyPatch(typeof(PlayerControllerB), "Jump_performed")] [HarmonyPrefix] public static void JumpPerformedPrefix(PlayerControllerB __instance) { if (((NetworkBehaviour)__instance).IsOwner && __instance.isPlayerControlled) { currentSprintMeter = __instance.sprintMeter; } } [HarmonyPatch(typeof(PlayerControllerB), "Jump_performed")] [HarmonyPostfix] public static void JumpPerformedPostfix(PlayerControllerB __instance) { if (((NetworkBehaviour)__instance).IsOwner && __instance.isPlayerControlled) { float num = __instance.sprintMeter - currentSprintMeter; if (num < 0f) { __instance.sprintMeter = Mathf.Max(new float[1] { currentSprintMeter + num * ConfigSync.instance.jumpStaminaConsumptionMultiplier }); } } } [HarmonyPatch(typeof(PlayerControllerB), "Update")] [HarmonyTranspiler] public static IEnumerable<CodeInstruction> SpoofWeightValuesUpdate(IEnumerable<CodeInstruction> instructions) { //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Expected O, but got Unknown List<CodeInstruction> list = new List<CodeInstruction>(instructions); FieldInfo field = typeof(PlayerControllerB).GetField("carryWeight", BindingFlags.Instance | BindingFlags.Public); MethodInfo method = typeof(PlayerPatcher).GetMethod("GetAdjustedWeight", BindingFlags.Static | BindingFlags.Public); for (int i = 0; i < list.Count; i++) { if (list[i].opcode == OpCodes.Ldfld && (FieldInfo)list[i].operand == field) { list[i] = new CodeInstruction(OpCodes.Call, (object)method); list.RemoveAt(i - 1); } } return list.AsEnumerable(); } [HarmonyPatch(typeof(PlayerControllerB), "LateUpdate")] [HarmonyTranspiler] public static IEnumerable<CodeInstruction> SpoofWeightValuesLateUpdate(IEnumerable<CodeInstruction> instructions) { //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Expected O, but got Unknown List<CodeInstruction> list = new List<CodeInstruction>(instructions); FieldInfo field = typeof(PlayerControllerB).GetField("carryWeight", BindingFlags.Instance | BindingFlags.Public); MethodInfo method = typeof(PlayerPatcher).GetMethod("GetAdjustedWeight", BindingFlags.Static | BindingFlags.Public); for (int i = 0; i < list.Count; i++) { if (list[i].opcode == OpCodes.Ldfld && (FieldInfo)list[i].operand == field) { list[i] = new CodeInstruction(OpCodes.Call, (object)method); list.RemoveAt(i - 1); } } return list.AsEnumerable(); } public static float GetAdjustedWeight() { return Mathf.Max(((Object)(object)StartOfRound.Instance.localPlayerController != (Object)null) ? (StartOfRound.Instance.localPlayerController.carryWeight * ConfigSync.instance.carryWeightPenaltyMultiplier) : 1f, 1f); } } } namespace BetterStamina.Config { [Serializable] public static class ConfigSettings { public static ConfigEntry<float> staminaRegenMultiplierConfig; public static ConfigEntry<float> staminaConsumptionMultiplierConfig; public static ConfigEntry<float> jumpStaminaConsumptionMultiplierConfig; public static ConfigEntry<float> carryWeightPenaltyMultiplierConfig; public static ConfigEntry<float> movementSpeedMultiplierConfig; public static void BindConfigSettings() { Plugin.Log("BindingConfigs"); staminaRegenMultiplierConfig = ((BaseUnityPlugin)Plugin.instance).Config.Bind<float>("BetterStamina", "StaminaRegenMultiplier", 1.5f, "Multiplier for how fast your stamina regens."); staminaConsumptionMultiplierConfig = ((BaseUnityPlugin)Plugin.instance).Config.Bind<float>("BetterStamina", "StaminaConsumptionMultiplier", 0.75f, "Multiplier for how much stamina drains while sprinting."); jumpStaminaConsumptionMultiplierConfig = ((BaseUnityPlugin)Plugin.instance).Config.Bind<float>("BetterStamina", "JumpStaminaConsumptionMultiplier", 0.75f, "Multiplier for how much stamina jumping consumes."); carryWeightPenaltyMultiplierConfig = ((BaseUnityPlugin)Plugin.instance).Config.Bind<float>("BetterStamina", "CarryWeightPenaltyMultiplier", 0.5f, "Multiplier for how much your speed/stamina consumption are affected by weight."); movementSpeedMultiplierConfig = ((BaseUnityPlugin)Plugin.instance).Config.Bind<float>("BetterStamina", "MovementSpeedMultiplier", 1f, "Player movement speed multiplier."); } } [Serializable] [HarmonyPatch] public class ConfigSync { public static ConfigSync defaultConfig; public static ConfigSync instance; public static PlayerControllerB localPlayerController; public static bool isSynced = false; private static float defaultMovementSpeed = 4.6f; public float staminaRegenMultiplier = 1f; public float staminaConsumptionMultiplier = 1f; public float jumpStaminaConsumptionMultiplier = 1f; public float carryWeightPenaltyMultiplier = 1f; public float movementSpeedMultiplier = 1f; public static void BuildDefaultConfigSync() { instance = new ConfigSync(); } public static void BuildServerConfigSync() { if (defaultConfig == null) { defaultConfig = new ConfigSync(); defaultConfig.staminaRegenMultiplier = ConfigSettings.staminaRegenMultiplierConfig.Value; defaultConfig.staminaConsumptionMultiplier = ConfigSettings.staminaConsumptionMultiplierConfig.Value; defaultConfig.jumpStaminaConsumptionMultiplier = ConfigSettings.jumpStaminaConsumptionMultiplierConfig.Value; defaultConfig.carryWeightPenaltyMultiplier = ConfigSettings.carryWeightPenaltyMultiplierConfig.Value; defaultConfig.movementSpeedMultiplier = ConfigSettings.movementSpeedMultiplierConfig.Value; instance = defaultConfig; } } [HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")] [HarmonyPostfix] public static void InitializeLocalPlayer(PlayerControllerB __instance) { //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Expected O, but got Unknown //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Expected O, but got Unknown localPlayerController = __instance; if (NetworkManager.Singleton.IsServer) { BuildServerConfigSync(); NetworkManager.Singleton.CustomMessagingManager.RegisterNamedMessageHandler("BetterStamina-OnRequestConfigSync", new HandleNamedMessageDelegate(OnReceiveConfigSyncRequest)); OnLocalClientConfigSync(); } else { isSynced = false; BuildDefaultConfigSync(); NetworkManager.Singleton.CustomMessagingManager.RegisterNamedMessageHandler("BetterStamina-OnReceiveConfigSync", new HandleNamedMessageDelegate(OnReceiveConfigSync)); RequestConfigSync(); } } public static void RequestConfigSync() { //IL_0036: Unknown result type (might be due to invalid IL or missing references) if (NetworkManager.Singleton.IsClient) { Plugin.Log("Sending config sync request to server."); FastBufferWriter val = default(FastBufferWriter); ((FastBufferWriter)(ref val))..ctor(4, (Allocator)2, -1); NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("BetterStamina-OnRequestConfigSync", 0uL, val, (NetworkDelivery)3); } else { Plugin.LogError("Failed to send config sync request."); } } public static void OnReceiveConfigSyncRequest(ulong clientId, FastBufferReader reader) { //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) if (NetworkManager.Singleton.IsServer) { Plugin.Log("Receiving config sync request from client with id: " + clientId + ". Sending config sync to client."); byte[] array = SerializeConfigToByteArray(instance); FastBufferWriter val = default(FastBufferWriter); ((FastBufferWriter)(ref val))..ctor(array.Length + 4, (Allocator)2, -1); int num = array.Length; ((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref num, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteBytesSafe(array, -1, 0); NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("BetterStamina-OnReceiveConfigSync", clientId, val, (NetworkDelivery)3); } } public static void OnReceiveConfigSync(ulong clientId, FastBufferReader reader) { //IL_0014: 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) if (((FastBufferReader)(ref reader)).TryBeginRead(4)) { int num = default(int); ((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num, default(ForPrimitives)); if (((FastBufferReader)(ref reader)).TryBeginRead(num)) { Plugin.Log("Receiving config sync from server."); byte[] data = new byte[num]; ((FastBufferReader)(ref reader)).ReadBytesSafe(ref data, num, 0); instance = DeserializeFromByteArray(data); OnLocalClientConfigSync(); } else { Plugin.LogError("Error receiving sync from server."); } } else { Plugin.LogError("Error receiving bytes length."); } } public static void OnLocalClientConfigSync() { localPlayerController.movementSpeed = defaultMovementSpeed * instance.movementSpeedMultiplier; isSynced = true; } public static byte[] SerializeConfigToByteArray(ConfigSync config) { BinaryFormatter binaryFormatter = new BinaryFormatter(); MemoryStream memoryStream = new MemoryStream(); binaryFormatter.Serialize(memoryStream, config); return memoryStream.ToArray(); } public static ConfigSync DeserializeFromByteArray(byte[] data) { MemoryStream serializationStream = new MemoryStream(data); BinaryFormatter binaryFormatter = new BinaryFormatter(); return (ConfigSync)binaryFormatter.Deserialize(serializationStream); } } }
plugins/FlipMods-FasterItemDropship/FasterItemDropship.dll
Decompiled 10 months agousing System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Unity.Netcode; 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("FasterItemDropship")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("Mod made by flipf17")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("FasterItemDropship")] [assembly: AssemblyCopyright("Copyright © 2023")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("a5a250fd-b706-48b9-9be9-da360fd939dc")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("1.0.0.0")] namespace FasterItemDropship { public static class ConfigSettings { public static ConfigEntry<int> dropshipDeliveryTime; public static ConfigEntry<int> dropshipMaxStayDuration; public static ConfigEntry<int> dropshipLeaveAfterSecondsOpenDoors; public static void BindConfigSettings() { Plugin.Log("BindingConfigs"); dropshipDeliveryTime = ((BaseUnityPlugin)Plugin.instance).Config.Bind<int>("FasterItemDropship", "DeliveryTime", 10, "How long it takes (in seconds) for the item dropship to arrive."); dropshipMaxStayDuration = ((BaseUnityPlugin)Plugin.instance).Config.Bind<int>("FasterItemDropship", "MaxLandDuration", 40, "The max duration (in seconds) the item dropship will stay."); dropshipLeaveAfterSecondsOpenDoors = ((BaseUnityPlugin)Plugin.instance).Config.Bind<int>("FasterItemDropship", "LeaveAfterSecondsOpenDoors", 3, "How long (in seconds) the item dropship will stay for after opening its doors."); } } [BepInPlugin("FlipMods.FasterItemDropship", "FasterItemDropship", "1.2.1")] public class Plugin : BaseUnityPlugin { private Harmony _harmony; public static Plugin instance; private void Awake() { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Expected O, but got Unknown instance = this; ConfigSettings.BindConfigSettings(); _harmony = new Harmony("FasterItemDropship"); _harmony.PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"FasterItemDropship loaded"); } public static void Log(string message) { ((BaseUnityPlugin)instance).Logger.LogInfo((object)message); } } public static class PluginInfo { public const string PLUGIN_GUID = "FlipMods.FasterItemDropship"; public const string PLUGIN_NAME = "FasterItemDropship"; public const string PLUGIN_VERSION = "1.2.1"; } } namespace FasterItemDropship.Patches { [HarmonyPatch] internal class FasterItemDropshipPatcher { private static Terminal terminalScript; private static StartOfRound playersManager; private static List<int> itemsToDeliver; private static List<int> orderedItemsFromTerminal; [HarmonyPatch(typeof(ItemDropship), "Start")] [HarmonyPrefix] public static void InitializeDropship(ItemDropship __instance) { playersManager = Object.FindObjectOfType<StartOfRound>(); terminalScript = Object.FindObjectOfType<Terminal>(); itemsToDeliver = (List<int>)Traverse.Create((object)__instance).Field("itemsToDeliver").GetValue(); } [HarmonyPatch(typeof(Terminal), "Start")] [HarmonyPrefix] public static void InitializeTerminal(Terminal __instance) { orderedItemsFromTerminal = __instance.orderedItemsFromTerminal; } [HarmonyPatch(typeof(ItemDropship), "Update")] [HarmonyPrefix] public static void DropshipUpdate(ItemDropship __instance) { if (((NetworkBehaviour)__instance).IsServer && !__instance.deliveringOrder && terminalScript.orderedItemsFromTerminal.Count > 0 && !playersManager.shipHasLanded) { __instance.shipTimer += Time.deltaTime; } } [HarmonyPatch(typeof(ItemDropship), "Update")] private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { List<CodeInstruction> list = new List<CodeInstruction>(instructions); for (int i = 0; i < list.Count; i++) { if (list[i].opcode == OpCodes.Ldc_R4) { if ((float)list[i].operand == 20f) { list[i].operand = (float)ConfigSettings.dropshipMaxStayDuration.Value; } else if ((float)list[i].operand == 40f) { list[i].operand = (float)(ConfigSettings.dropshipMaxStayDuration.Value + ConfigSettings.dropshipDeliveryTime.Value); } else if ((float)list[i].operand == 30f) { list[i].operand = (float)ConfigSettings.dropshipMaxStayDuration.Value; break; } } } return list.AsEnumerable(); } [HarmonyPatch(typeof(ItemDropship), "OpenShipDoorsOnServer")] [HarmonyPostfix] public static void OnOpenShipDoors(ItemDropship __instance) { if (((NetworkBehaviour)__instance).IsServer) { __instance.shipTimer = Mathf.Max(__instance.shipTimer, (float)(ConfigSettings.dropshipMaxStayDuration.Value - ConfigSettings.dropshipLeaveAfterSecondsOpenDoors.Value)); } } [HarmonyPatch(typeof(ItemDropship), "ShipLandedAnimationEvent")] [HarmonyPrefix] public static void AddLateItemsServer(ItemDropship __instance) { if (((NetworkBehaviour)__instance).IsServer && !__instance.shipLanded && !__instance.shipDoorsOpened) { while (orderedItemsFromTerminal.Count > 0 && itemsToDeliver.Count < 12) { itemsToDeliver.Add(orderedItemsFromTerminal[0]); orderedItemsFromTerminal.RemoveAt(0); } } } } }
plugins/FlipMods-HotbarPlus/HotbarPlus.dll
Decompiled 10 months agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; 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 BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using GameNetcodeStuff; using HarmonyLib; using HotbarPlus.Config; using HotbarPlus.Input; using HotbarPlus.Patches; using LethalCompanyInputUtils.Api; using Unity.Collections; using Unity.Netcode; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("HotbarPlus")] [assembly: AssemblyDescription("Mod made by flipf17.")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("HotbarPlus")] [assembly: AssemblyCopyright("Copyright © 2023")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("fab060f0-b006-42ea-ba6f-473f4850c587")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("1.0.0.0")] namespace HotbarPlus { [HarmonyPatch] public class SyncManager { private static PlayerControllerB localPlayerController; [HarmonyPatch(typeof(StartOfRound), "Awake")] [HarmonyPostfix] public static void ResetValues() { ConfigSync.isSynced = false; } [HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")] [HarmonyPostfix] public static void Init(PlayerControllerB __instance) { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Expected O, but got Unknown //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Expected O, but got Unknown if ((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)(object)__instance) { localPlayerController = __instance; NetworkManager.Singleton.CustomMessagingManager.RegisterNamedMessageHandler("HotbarPlus-OnHotbarSlotChangeClientRpc", new HandleNamedMessageDelegate(OnHotbarSlotChangeClientRpc)); if (NetworkManager.Singleton.IsServer) { NetworkManager.Singleton.CustomMessagingManager.RegisterNamedMessageHandler("HotbarPlus-OnHotbarSlotChangeServerRpc", new HandleNamedMessageDelegate(OnHotbarSlotChangeServerRpc)); } } } private static void SendHotbarSlotChange(int hotbarSlot) { //IL_003b: 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_0059: Unknown result type (might be due to invalid IL or missing references) if (NetworkManager.Singleton.IsClient) { FastBufferWriter val = default(FastBufferWriter); ((FastBufferWriter)(ref val))..ctor(4, (Allocator)2, -1); Plugin.Log("Sending hotbar swap slot: " + hotbarSlot); ((FastBufferWriter)(ref val)).WriteValue<int>(ref hotbarSlot, default(ForPrimitives)); NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("HotbarPlus-OnHotbarSlotChangeServerRpc", 0uL, val, (NetworkDelivery)3); } } private static void OnHotbarSlotChangeServerRpc(ulong clientId, FastBufferReader reader) { //IL_001a: 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_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_006e: 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_008a: Unknown result type (might be due to invalid IL or missing references) if (NetworkManager.Singleton.IsServer) { int num = default(int); ((FastBufferReader)(ref reader)).ReadValue<int>(ref num, default(ForPrimitives)); Plugin.Log("Receiving request for hotbar swap. Slot: " + num + " ClientId: " + clientId); FastBufferWriter val = default(FastBufferWriter); ((FastBufferWriter)(ref val))..ctor(12, (Allocator)2, -1); ((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref num, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref clientId, default(ForPrimitives)); NetworkManager.Singleton.CustomMessagingManager.SendNamedMessageToAll("HotbarPlus-OnHotbarSlotChangeClientRpc", val, (NetworkDelivery)3); } } private static void OnHotbarSlotChangeClientRpc(ulong clientId, FastBufferReader reader) { //IL_002e: 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_0042: 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) if (!NetworkManager.Singleton.IsClient) { return; } if (((FastBufferReader)(ref reader)).TryBeginRead(12)) { int hotbarSlot = default(int); ((FastBufferReader)(ref reader)).ReadValue<int>(ref hotbarSlot, default(ForPrimitives)); ulong num = default(ulong); ((FastBufferReader)(ref reader)).ReadValue<ulong>(ref num, default(ForPrimitives)); Plugin.Log("Receiving update for hotbar swap. Slot: " + hotbarSlot + " ClientId: " + num); if (num == localPlayerController.actualClientId || UpdateClientHotbarSlot(num, hotbarSlot)) { return; } Plugin.Log("Failed to receive hotbar swap index from Client: " + num); } Plugin.Log("Failed to receive hotbar swap index from Client"); } private static bool UpdateClientHotbarSlot(ulong clientId, int hotbarSlot) { Plugin.Log("Updating hotbar slot: " + hotbarSlot + " ClientId: " + clientId); for (int i = 0; i < StartOfRound.Instance.allPlayerScripts.Length; i++) { if (StartOfRound.Instance.allPlayerScripts[i].actualClientId == clientId) { CallSwitchToItemSlotMethod(StartOfRound.Instance.allPlayerScripts[i], hotbarSlot); return true; } } return false; } public static void SwapHotbarSlot(int hotbarIndex) { if (hotbarIndex < PlayerPatcher.targetHotbarSize) { SendHotbarSlotChange(hotbarIndex); CallSwitchToItemSlotMethod(localPlayerController, hotbarIndex); } } private static void CallSwitchToItemSlotMethod(PlayerControllerB playerController, int hotbarIndex) { if (hotbarIndex < PlayerPatcher.targetHotbarSize && playerController.currentItemSlot != hotbarIndex) { if ((Object)(object)playerController == (Object)(object)localPlayerController) { ShipBuildModeManager.Instance.CancelBuildMode(true); playerController.playerBodyAnimator.SetBool("GrabValidated", false); } MethodInfo method = ((object)playerController).GetType().GetMethod("SwitchToItemSlot", BindingFlags.Instance | BindingFlags.NonPublic); method.Invoke(playerController, new object[2] { hotbarIndex, null }); PlayerPatcher.SetTimeSinceSwitchingSlots(playerController, 0f); if ((Object)(object)playerController.currentlyHeldObjectServer != (Object)null) { ((Component)playerController.currentlyHeldObjectServer).gameObject.GetComponent<AudioSource>().PlayOneShot(playerController.currentlyHeldObjectServer.itemProperties.grabSFX, 0.6f); } } } } [BepInPlugin("FlipMods.HotbarPlus", "HotbarPlus", "1.5.7")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { public static Plugin instance; private Harmony _harmony; private void Awake() { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown instance = this; _harmony = new Harmony("HotbarPlus"); ConfigSettings.BindConfigSettings(); Keybinds.InitKeybinds(); _harmony.PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"HotbarPlus loaded"); } public static bool IsModLoaded(string guid) { return Chainloader.PluginInfos.ContainsKey(guid); } public static void Log(string message) { ((BaseUnityPlugin)instance).Logger.LogInfo((object)message); } public static void LogError(string message) { ((BaseUnityPlugin)instance).Logger.LogError((object)message); } } public static class PluginInfo { public const string PLUGIN_GUID = "FlipMods.HotbarPlus"; public const string PLUGIN_NAME = "HotbarPlus"; public const string PLUGIN_VERSION = "1.5.7"; } } namespace HotbarPlus.Patches { [HarmonyPatch] public class HUDPatcher { public static float hotbarSlotSize = 40f; public static void ResizeHotbarSlotsHUD() { //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0090: 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_01a5: 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_01c3: Unknown result type (might be due to invalid IL or missing references) //IL_01eb: Unknown result type (might be due to invalid IL or missing references) //IL_024c: 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_0274: Unknown result type (might be due to invalid IL or missing references) //IL_028d: 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) List<Image> list = new List<Image>(HUDManager.Instance.itemSlotIconFrames); List<Image> list2 = new List<Image>(HUDManager.Instance.itemSlotIcons); float num = (hotbarSlotSize + ConfigSettings.overrideHotbarSpacing.Value) * ConfigSettings.overrideHotbarHudSize.Value; float num2 = ((Graphic)list[0]).rectTransform.anchoredPosition.y + 36f * ((ConfigSettings.overrideHotbarHudSize.Value - 1f) / 2f); Vector3 eulerAngles = ((Transform)((Graphic)list[0]).rectTransform).eulerAngles; Vector3 eulerAngles2 = ((Transform)((Graphic)list2[0]).rectTransform).eulerAngles; for (int i = 0; i < Mathf.Max(PlayerPatcher.targetHotbarSize, PlayerPatcher.initialHotbarSize); i++) { if (i >= PlayerPatcher.targetHotbarSize) { Object.Destroy((Object)(object)list[PlayerPatcher.targetHotbarSize]); Object.Destroy((Object)(object)list2[PlayerPatcher.targetHotbarSize]); list.RemoveAt(PlayerPatcher.targetHotbarSize); list2.RemoveAt(PlayerPatcher.targetHotbarSize); continue; } if (i >= PlayerPatcher.initialHotbarSize) { list.Insert(i, Object.Instantiate<Image>(list[i - 1], ((Component)list[0]).transform.parent)); ((Component)list[i]).transform.SetSiblingIndex(((Component)list[i - 1]).transform.GetSiblingIndex() + 1); list2.Insert(i, ((Component)((Component)list[i]).transform.GetChild(0)).GetComponent<Image>()); } ((Object)list[i]).name = $"Slot{i}"; ((Graphic)list[i]).rectTransform.anchoredPosition = Vector2.up * num2; ((Transform)((Graphic)list[i]).rectTransform).eulerAngles = eulerAngles; ((Object)list2[i]).name = "Icon"; ((Transform)((Graphic)list2[i]).rectTransform).eulerAngles = eulerAngles2; } float num3 = num * (float)(PlayerPatcher.targetHotbarSize - 1); float num4 = num3 / 2f; for (int j = 0; j < PlayerPatcher.targetHotbarSize; j++) { float num5 = (float)j * num - num4; ((Graphic)list[j]).rectTransform.anchoredPosition = new Vector2(num5, num2); RectTransform rectTransform = ((Graphic)list[j]).rectTransform; rectTransform.sizeDelta *= ConfigSettings.overrideHotbarHudSize.Value; RectTransform rectTransform2 = ((Graphic)list2[j]).rectTransform; rectTransform2.sizeDelta *= ConfigSettings.overrideHotbarHudSize.Value; } HUDManager.Instance.itemSlotIconFrames = list.ToArray(); HUDManager.Instance.itemSlotIcons = list2.ToArray(); } [HarmonyPatch(typeof(HUDManager), "PingHUDElement")] [HarmonyPrefix] public static void PingHUDElement(HUDElement element, ref float startAlpha, ref float endAlpha, HUDManager __instance) { if (element != __instance.Inventory || endAlpha != 0.13f) { return; } if (startAlpha == 0.13f && StartOfRound.Instance.localPlayerController.twoHanded) { endAlpha = 1f; return; } endAlpha = Mathf.Clamp(ConfigSettings.overrideFadeHudAlpha.Value, 0f, 1f); if (startAlpha == 0.13f) { startAlpha = endAlpha; } } } [HarmonyPatch] public class PlayerPatcher { public static PlayerControllerB localPlayerController; public static int initialHotbarSize = -1; public static int postInitialHotbarSize = -1; public static int targetHotbarSize = -1; public static int newHotbarSize = -1; public static float timeDroppedItem; [HarmonyPatch(typeof(PlayerControllerB), "Awake")] [HarmonyPostfix] public static void GetInitialHotbarSize(PlayerControllerB __instance) { if (initialHotbarSize == -1) { initialHotbarSize = __instance.ItemSlots.Length; } } [HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")] [HarmonyPostfix] public static void InitializeLocalPlayer(PlayerControllerB __instance) { localPlayerController = __instance; ((Component)HUDManager.Instance.itemSlotIconFrames[Mathf.Max(__instance.currentItemSlot, 0)]).GetComponent<Animator>().SetBool("selectedSlot", true); HUDManager.Instance.PingHUDElement(HUDManager.Instance.Inventory, 0.1f, 0.13f, 0.13f); } public static void ResizeInventory() { postInitialHotbarSize = localPlayerController.ItemSlots.Length; targetHotbarSize = Mathf.Clamp(ConfigSync.instance.hotbarSize, 0, 10); newHotbarSize = Mathf.Clamp(ConfigSync.instance.hotbarSize + (postInitialHotbarSize - initialHotbarSize), 0, 10); for (int i = 0; i < StartOfRound.Instance.allPlayerScripts.Length; i++) { PlayerControllerB val = StartOfRound.Instance.allPlayerScripts[i]; val.ItemSlots = (GrabbableObject[])(object)new GrabbableObject[newHotbarSize]; } } [HarmonyPatch(typeof(PlayerControllerB), "ScrollMouse_performed")] [HarmonyPrefix] public static bool PreventItemSwapWhileDroppingItem(PlayerControllerB __instance) { return true; } public static int CallGetNextItemSlot(PlayerControllerB __instance, bool forward, int index) { int currentItemSlot = __instance.currentItemSlot; __instance.currentItemSlot = index; MethodInfo method = ((object)__instance).GetType().GetMethod("NextItemSlot", BindingFlags.Instance | BindingFlags.NonPublic); index = (int)method.Invoke(__instance, new object[1] { forward }); __instance.currentItemSlot = currentItemSlot; return index; } public static void CallSwitchToItemSlot(PlayerControllerB __instance, int index, GrabbableObject fillSlotWithItem = null) { MethodInfo method = ((object)__instance).GetType().GetMethod("SwitchToItemSlot", BindingFlags.Instance | BindingFlags.NonPublic); method.Invoke(__instance, new object[2] { index, fillSlotWithItem }); SetTimeSinceSwitchingSlots(__instance, 0f); } public static float GetTimeSinceSwitchingSlots(PlayerControllerB playerController) { return (float)Traverse.Create((object)playerController).Field("timeSinceSwitchingSlots").GetValue(); } public static void SetTimeSinceSwitchingSlots(PlayerControllerB playerController, float value) { Traverse.Create((object)playerController).Field("timeSinceSwitchingSlots").SetValue((object)value); } [HarmonyPatch(typeof(PlayerControllerB), "ScrollMouse_performed")] [HarmonyTranspiler] private static IEnumerable<CodeInstruction> PatchSwitchItemInterval(IEnumerable<CodeInstruction> instructions) { List<CodeInstruction> list = new List<CodeInstruction>(instructions); if (!ConfigSettings.disableFasterHotbarSwapping.Value) { for (int i = 0; i < list.Count; i++) { if (list[i].opcode == OpCodes.Ldc_R4 && (float)list[i].operand == 0.3f) { list[i].operand = ConfigSettings.minSwapItemInterval; break; } } } return list.AsEnumerable(); } [HarmonyPatch(typeof(PlayerControllerB), "ActivateItem_performed")] [HarmonyTranspiler] private static IEnumerable<CodeInstruction> PatchActivateItemInterval(IEnumerable<CodeInstruction> instructions) { List<CodeInstruction> list = new List<CodeInstruction>(instructions); if (!ConfigSettings.disableFasterItemActivate.Value) { for (int i = 0; i < list.Count; i++) { if (list[i].opcode == OpCodes.Ldc_R4 && (float)list[i].operand == 0.075f) { list[i].operand = ConfigSettings.minActivateItemInterval; break; } } } return list.AsEnumerable(); } [HarmonyPatch(typeof(PlayerControllerB), "Discard_performed")] [HarmonyTranspiler] private static IEnumerable<CodeInstruction> PatchDiscardItemInterval(IEnumerable<CodeInstruction> instructions) { List<CodeInstruction> list = new List<CodeInstruction>(instructions); if (!ConfigSettings.disableFasterItemDropping.Value) { for (int i = 0; i < list.Count; i++) { if (list[i].opcode == OpCodes.Ldc_R4 && (float)list[i].operand == 0.2f) { list[i].operand = ConfigSettings.minDiscardItemInterval; } } } return list.AsEnumerable(); } [HarmonyPatch(typeof(PlayerControllerB), "Interact_performed")] [HarmonyTranspiler] private static IEnumerable<CodeInstruction> PatchInteractInterval(IEnumerable<CodeInstruction> instructions) { List<CodeInstruction> list = new List<CodeInstruction>(instructions); for (int i = 0; i < list.Count; i++) { if (list[i].opcode == OpCodes.Ldc_R4 && (float)list[i].operand == 0.2f) { list[i].operand = ConfigSettings.minInteractInterval; break; } } return list.AsEnumerable(); } [HarmonyPatch(typeof(PlayerControllerB), "PerformEmote")] [HarmonyTranspiler] private static IEnumerable<CodeInstruction> PatchPerformEmoteInterval(IEnumerable<CodeInstruction> instructions) { List<CodeInstruction> list = new List<CodeInstruction>(instructions); for (int i = 0; i < list.Count; i++) { if (list[i].opcode == OpCodes.Ldc_R4 && (float)list[i].operand == 0.5f) { list[i].operand = ConfigSettings.minUseEmoteInterval; break; } } return list.AsEnumerable(); } [HarmonyPatch(typeof(PlayerControllerB), "ScrollMouse_performed")] [HarmonyTranspiler] private static IEnumerable<CodeInstruction> InvertHotbarScrollDirection(IEnumerable<CodeInstruction> instructions) { List<CodeInstruction> list = new List<CodeInstruction>(instructions); if (ConfigSettings.invertHotbarScrollDirectionConfig.Value) { for (int i = 1; i < list.Count; i++) { if (list[i].opcode == OpCodes.Ble_Un && list[i - 1].opcode == OpCodes.Ldc_R4 && (float)list[i - 1].operand == 0f) { list[i].opcode = OpCodes.Bge_Un; break; } } } return list.AsEnumerable(); } } [HarmonyPatch] public class QuickDrop { public static float timeDroppedItem; public static bool droppingItem; public static PlayerControllerB localPlayerController => StartOfRound.Instance?.localPlayerController; [HarmonyPatch(typeof(PlayerControllerB), "DiscardHeldObject")] [HarmonyPostfix] public static void PerformQuickDiscard(PlayerControllerB __instance) { if ((Object)(object)__instance != (Object)(object)localPlayerController || !ConfigSettings.useItemQuickDropConfig.Value || !ConfigSync.isSynced) { return; } localPlayerController.playerBodyAnimator.SetBool("cancelGrab", false); int num; for (num = PlayerPatcher.CallGetNextItemSlot(__instance, forward: true, __instance.currentItemSlot); num != __instance.currentItemSlot; num = PlayerPatcher.CallGetNextItemSlot(__instance, forward: true, num)) { GrabbableObject val = __instance.ItemSlots[num]; if ((Object)(object)val != (Object)null) { break; } } if (num != __instance.currentItemSlot) { droppingItem = true; PlayerPatcher.SetTimeSinceSwitchingSlots(__instance, 0f); __instance.playerBodyAnimator.ResetTrigger("SwitchHoldAnimation"); ((MonoBehaviour)__instance).StartCoroutine(SwitchToItemSlotAfterDelay(__instance, num)); } } private static IEnumerator SwitchToItemSlotAfterDelay(PlayerControllerB __instance, int slot) { if (!ConfigSettings.disableFasterHotbarSwapping.Value) { _ = ConfigSettings.minSwapItemInterval; } timeDroppedItem = Time.time; yield return (object)new WaitUntil((Func<bool>)(() => (Object)(object)__instance.currentlyHeldObjectServer == (Object)null)); _ = Time.time - timeDroppedItem; SyncManager.SwapHotbarSlot(slot); droppingItem = false; } [HarmonyPatch(typeof(PlayerControllerB), "ScrollMouse_performed")] [HarmonyPrefix] public static bool PreventItemSwappingDroppingItem(CallbackContext context, PlayerControllerB __instance) { if ((Object)(object)__instance == (Object)(object)localPlayerController && droppingItem) { return false; } return true; } } } namespace HotbarPlus.Input { internal class IngameKeybinds : LcInputActions { internal static IngameKeybinds Instance = new IngameKeybinds(); [InputAction("<Keyboard>/1", Name = "[HB+] Quick Slot 1")] public InputAction QuickHotbarSlotHotkey1 { get; set; } [InputAction("<Keyboard>/2", Name = "[HB+] Quick Slot 2")] public InputAction QuickHotbarSlotHotkey2 { get; set; } [InputAction("<Keyboard>/3", Name = "[HB+] Quick Slot 3")] public InputAction QuickHotbarSlotHotkey3 { get; set; } [InputAction("<Keyboard>/4", Name = "[HB+] Quick Slot 4")] public InputAction QuickHotbarSlotHotkey4 { get; set; } [InputAction("<Keyboard>/5", Name = "[HB+] Quick Slot 5")] public InputAction QuickHotbarSlotHotkey5 { get; set; } [InputAction("<Keyboard>/6", Name = "[HB+] Quick Slot 6")] public InputAction QuickHotbarSlotHotkey6 { get; set; } internal static InputActionAsset GetAsset() { return ((LcInputActions)Instance).Asset; } } internal class InputUtilsCompat { internal static InputActionAsset Asset => IngameKeybinds.GetAsset(); internal static bool Enabled => Plugin.IsModLoaded("com.rune580.LethalCompanyInputUtils"); public static InputAction QuickHotbarSlotHotkey1 => IngameKeybinds.Instance.QuickHotbarSlotHotkey1; public static InputAction QuickHotbarSlotHotkey2 => IngameKeybinds.Instance.QuickHotbarSlotHotkey2; public static InputAction QuickHotbarSlotHotkey3 => IngameKeybinds.Instance.QuickHotbarSlotHotkey3; public static InputAction QuickHotbarSlotHotkey4 => IngameKeybinds.Instance.QuickHotbarSlotHotkey4; public static InputAction QuickHotbarSlotHotkey5 => IngameKeybinds.Instance.QuickHotbarSlotHotkey5; public static InputAction QuickHotbarSlotHotkey6 => IngameKeybinds.Instance.QuickHotbarSlotHotkey6; } [HarmonyPatch] public class Keybinds { private static bool setHotbarSize; public static InputActionAsset Asset; public static InputActionMap ActionMap; public static InputAction quickHotbarSlotHotkey1; public static InputAction quickHotbarSlotHotkey2; public static InputAction quickHotbarSlotHotkey3; public static InputAction quickHotbarSlotHotkey4; public static InputAction quickHotbarSlotHotkey5; public static InputAction quickHotbarSlotHotkey6; private static PlayerControllerB localPlayerController => StartOfRound.Instance?.localPlayerController; public static void InitKeybinds() { //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Expected O, but got Unknown //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Expected O, but got Unknown setHotbarSize = false; if (ConfigSettings.useHotbarNumberHotkeysConfig.Value) { if (InputUtilsCompat.Enabled) { Asset = InputUtilsCompat.Asset; quickHotbarSlotHotkey1 = InputUtilsCompat.QuickHotbarSlotHotkey1; quickHotbarSlotHotkey2 = InputUtilsCompat.QuickHotbarSlotHotkey2; quickHotbarSlotHotkey3 = InputUtilsCompat.QuickHotbarSlotHotkey3; quickHotbarSlotHotkey4 = InputUtilsCompat.QuickHotbarSlotHotkey4; quickHotbarSlotHotkey5 = InputUtilsCompat.QuickHotbarSlotHotkey5; quickHotbarSlotHotkey6 = InputUtilsCompat.QuickHotbarSlotHotkey6; } else { Asset = new InputActionAsset(); ActionMap = new InputActionMap("HotbarPlus"); quickHotbarSlotHotkey1 = InputActionSetupExtensions.AddAction(ActionMap, "[HB+] Quick Slot 1", (InputActionType)0, "<Keyboard>/1", "Press", (string)null, (string)null, (string)null); quickHotbarSlotHotkey2 = InputActionSetupExtensions.AddAction(ActionMap, "[HB+] Quick Slot 2", (InputActionType)0, "<Keyboard>/2", "Press", (string)null, (string)null, (string)null); quickHotbarSlotHotkey3 = InputActionSetupExtensions.AddAction(ActionMap, "[HB+] Quick Slot 3", (InputActionType)0, "<Keyboard>/3", "Press", (string)null, (string)null, (string)null); quickHotbarSlotHotkey4 = InputActionSetupExtensions.AddAction(ActionMap, "[HB+] Quick Slot 4", (InputActionType)0, "<Keyboard>/4", "Press", (string)null, (string)null, (string)null); quickHotbarSlotHotkey5 = InputActionSetupExtensions.AddAction(ActionMap, "[HB+] Quick Slot 5", (InputActionType)0, "<Keyboard>/5", "Press", (string)null, (string)null, (string)null); quickHotbarSlotHotkey6 = InputActionSetupExtensions.AddAction(ActionMap, "[HB+] Quick Slot 6", (InputActionType)0, "<Keyboard>/6", "Press", (string)null, (string)null, (string)null); InputActionSetupExtensions.AddActionMap(Asset, ActionMap); } } } public static void OnSetHotbarSize() { setHotbarSize = true; } [HarmonyPatch(typeof(StartOfRound), "OnEnable")] [HarmonyPostfix] public static void OnEnable() { if (ConfigSettings.useHotbarNumberHotkeysConfig.Value) { Asset.Enable(); quickHotbarSlotHotkey1.performed += OnPressItemSlotHotkeyAction1; quickHotbarSlotHotkey2.performed += OnPressItemSlotHotkeyAction2; quickHotbarSlotHotkey3.performed += OnPressItemSlotHotkeyAction3; quickHotbarSlotHotkey4.performed += OnPressItemSlotHotkeyAction4; quickHotbarSlotHotkey5.performed += OnPressItemSlotHotkeyAction5; quickHotbarSlotHotkey6.performed += OnPressItemSlotHotkeyAction6; } } [HarmonyPatch(typeof(StartOfRound), "OnDisable")] [HarmonyPostfix] public static void OnDisable() { if (ConfigSettings.useHotbarNumberHotkeysConfig.Value) { Asset.Disable(); quickHotbarSlotHotkey1.performed -= OnPressItemSlotHotkeyAction1; quickHotbarSlotHotkey2.performed -= OnPressItemSlotHotkeyAction2; quickHotbarSlotHotkey3.performed -= OnPressItemSlotHotkeyAction3; quickHotbarSlotHotkey4.performed -= OnPressItemSlotHotkeyAction4; quickHotbarSlotHotkey5.performed -= OnPressItemSlotHotkeyAction5; quickHotbarSlotHotkey6.performed -= OnPressItemSlotHotkeyAction6; } } private static void OnPressItemSlotHotkeyAction1(CallbackContext context) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) OnPressItemSlotHotkeyAction(context, 0); } private static void OnPressItemSlotHotkeyAction2(CallbackContext context) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) OnPressItemSlotHotkeyAction(context, 1); } private static void OnPressItemSlotHotkeyAction3(CallbackContext context) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) OnPressItemSlotHotkeyAction(context, 2); } private static void OnPressItemSlotHotkeyAction4(CallbackContext context) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) OnPressItemSlotHotkeyAction(context, 3); } private static void OnPressItemSlotHotkeyAction5(CallbackContext context) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) OnPressItemSlotHotkeyAction(context, 4); } private static void OnPressItemSlotHotkeyAction6(CallbackContext context) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) OnPressItemSlotHotkeyAction(context, 5); } private static void OnPressItemSlotHotkeyAction(CallbackContext context, int slot) { if (ConfigSettings.useHotbarNumberHotkeysConfig.Value && setHotbarSize && !((Object)(object)localPlayerController == (Object)null) && ((NetworkBehaviour)localPlayerController).IsOwner && localPlayerController.isPlayerControlled && slot >= 0 && slot < ConfigSync.instance.hotbarSize && ((CallbackContext)(ref context)).performed && !(bool)Traverse.Create((object)localPlayerController).Field("throwingObject").GetValue() && !localPlayerController.isTypingChat && !localPlayerController.inTerminalMenu && !localPlayerController.twoHanded && !(PlayerPatcher.GetTimeSinceSwitchingSlots(localPlayerController) < ((!ConfigSettings.disableFasterHotbarSwapping.Value) ? ConfigSettings.minSwapItemInterval : 0.3f))) { SyncManager.SwapHotbarSlot(slot); } } } } namespace HotbarPlus.Config { public static class ConfigSettings { public static ConfigEntry<int> hotbarSizeConfig; public static ConfigEntry<bool> useHotbarNumberHotkeysConfig; public static ConfigEntry<bool> invertHotbarScrollDirectionConfig; public static ConfigEntry<float> overrideHotbarSpacing; public static ConfigEntry<float> overrideFadeHudAlpha; public static ConfigEntry<float> overrideHotbarHudSize; public static ConfigEntry<bool> useItemQuickDropConfig; public static ConfigEntry<bool> disableFasterHotbarSwapping; public static ConfigEntry<bool> disableFasterItemDropping; public static ConfigEntry<bool> disableFasterItemActivate; public static Dictionary<string, ConfigEntryBase> currentConfigEntries = new Dictionary<string, ConfigEntryBase>(); public static float minSwapItemInterval = 0.05f; public static float minActivateItemInterval = 0.05f; public static float minDiscardItemInterval = 0.05f; public static float minInteractInterval = 0.05f; public static float minUseEmoteInterval = 0.25f; public static List<ConfigEntryBase> configEntries = new List<ConfigEntryBase>(); public static void BindConfigSettings() { Plugin.Log("BindingConfigs"); hotbarSizeConfig = AddConfigEntry<int>(((BaseUnityPlugin)Plugin.instance).Config.Bind<int>("Server-side", "HotbarSize", 4, "[Host only] The amount of hotbar slots player will have. This will sync with other clients who have the mod.")); useHotbarNumberHotkeysConfig = AddConfigEntry<bool>(((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Client-side", "UseHotbarNumberHotkeys", true, "Use the quick item selection numerical hotkeys.")); invertHotbarScrollDirectionConfig = AddConfigEntry<bool>(((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Client-side", "InvertHotbarScrollDirection", true, "Inverts the direction in which you scroll on the hotbar. Will not affect the terminal scrolling direction.")); overrideHotbarSpacing = AddConfigEntry<float>(((BaseUnityPlugin)Plugin.instance).Config.Bind<float>("Client-side", "OverrideHotbarHudSpacing", 10f, "The spacing between each hotbar slot UI element. Not recommended to go below 0... But no one is stopping you.")); overrideFadeHudAlpha = AddConfigEntry<float>(((BaseUnityPlugin)Plugin.instance).Config.Bind<float>("Client-side", "OverrideFadeHudAlpha", 0.13f, "Sets the alpha for when the hotbar hud fades. Default = 0.13 | Fade completely: 0 | Never fade: 1")); overrideHotbarHudSize = AddConfigEntry<float>(((BaseUnityPlugin)Plugin.instance).Config.Bind<float>("Client-side", "OverrideHotbarHudSize", 1f, "Scales the hotbar slot HUD elements by a multiplier. HUD spacing and position will be scaled/adjusted automatically.")); useItemQuickDropConfig = AddConfigEntry<bool>(((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Client-side", "UseItemQuickDropConfig", true, "If enabled, dropping an item will automatically swap to the next item for easier chain dropping. This may not work if the host does not have the mod. This is for stability reasons, and to help reduce de-sync.")); disableFasterHotbarSwapping = AddConfigEntry<bool>(((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Client-side", "UseDefaultItemSwapInterval", false, "If true, the interval (delay) between swapping items will not be reduced by this mod.")); disableFasterItemDropping = AddConfigEntry<bool>(((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Client-side", "UseDefaultItemDropInterval", false, "If true, the interval (delay) between dropping items will not be reduced by this mod.")); disableFasterItemActivate = AddConfigEntry<bool>(((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Client-side", "UseDefaultItemActivateInterval", false, "If true, the interval (delay) between activating items will not be reduced by this mod.")); TryRemoveOldConfigSettings(); ConfigSync.BuildDefaultConfig(); } public static ConfigEntry<T> AddConfigEntry<T>(ConfigEntry<T> configEntry) { currentConfigEntries.Add(((ConfigEntryBase)configEntry).Definition.Key, (ConfigEntryBase)(object)configEntry); return configEntry; } public static void TryRemoveOldConfigSettings() { HashSet<string> hashSet = new HashSet<string>(); HashSet<string> hashSet2 = new HashSet<string>(); foreach (ConfigEntryBase value in currentConfigEntries.Values) { hashSet.Add(value.Definition.Section); hashSet2.Add(value.Definition.Key); } try { Plugin.Log("Cleaning old config entries"); ConfigFile config = ((BaseUnityPlugin)Plugin.instance).Config; string configFilePath = config.ConfigFilePath; if (!File.Exists(configFilePath)) { return; } string text = File.ReadAllText(configFilePath); string[] array = File.ReadAllLines(configFilePath); string text2 = ""; for (int i = 0; i < array.Length; i++) { array[i] = array[i].Replace("\n", ""); if (array[i].Length <= 0) { continue; } if (array[i].StartsWith("[")) { if (text2 != "" && !hashSet.Contains(text2)) { text2 = "[" + text2 + "]"; int num = text.IndexOf(text2); int num2 = text.IndexOf(array[i]); text = text.Remove(num, num2 - num); } text2 = array[i].Replace("[", "").Replace("]", "").Trim(); } else { if (!(text2 != "")) { continue; } if (i <= array.Length - 4 && array[i].StartsWith("##")) { int j; for (j = 1; i + j < array.Length && array[i + j].Length > 3; j++) { } if (hashSet.Contains(text2)) { int num3 = array[i + j - 1].IndexOf("="); string item = array[i + j - 1].Substring(0, num3 - 1); if (!hashSet2.Contains(item)) { int num4 = text.IndexOf(array[i]); int num5 = text.IndexOf(array[i + j - 1]) + array[i + j - 1].Length; text = text.Remove(num4, num5 - num4); } } i += j - 1; } else if (array[i].Length > 3) { text = text.Replace(array[i], ""); } } } if (!hashSet.Contains(text2)) { text2 = "[" + text2 + "]"; int num6 = text.IndexOf(text2); text = text.Remove(num6, text.Length - num6); } while (text.Contains("\n\n\n")) { text = text.Replace("\n\n\n", "\n\n"); } File.WriteAllText(configFilePath, text); config.Reload(); } catch { } } } [HarmonyPatch] public class ConfigSync { public static ConfigSync defaultConfig; public static ConfigSync instance; public static PlayerControllerB localPlayerController; public static bool isSynced; public int hotbarSize = 4; public ConfigSync() { hotbarSize = ConfigSettings.hotbarSizeConfig.Value; } public static void BuildDefaultConfig() { defaultConfig = new ConfigSync(); } [HarmonyPatch(typeof(StartOfRound), "Awake")] [HarmonyPostfix] public static void ResetValues() { isSynced = false; } [HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")] [HarmonyPostfix] public static void InitializeLocalPlayer(PlayerControllerB __instance) { //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Expected O, but got Unknown //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown localPlayerController = __instance; if (NetworkManager.Singleton.IsServer) { NetworkManager.Singleton.CustomMessagingManager.RegisterNamedMessageHandler("HotbarPlusOnRequestConfigSync", new HandleNamedMessageDelegate(OnReceiveConfigSyncRequest)); instance = defaultConfig; OnLocalClientConfigSync(); } else { instance = new ConfigSync(); instance.hotbarSize = 4; isSynced = false; NetworkManager.Singleton.CustomMessagingManager.RegisterNamedMessageHandler("HotbarPlusOnReceiveConfigSync", new HandleNamedMessageDelegate(OnReceiveConfigSync)); RequestConfigSync(); } } public static void RequestConfigSync() { //IL_002f: Unknown result type (might be due to invalid IL or missing references) if (NetworkManager.Singleton.IsClient) { Plugin.Log("Sending config sync request to server."); NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("HotbarPlusOnRequestConfigSync", 0uL, new FastBufferWriter(0, (Allocator)2, -1), (NetworkDelivery)3); } else { Plugin.LogError("Failed to send config sync request."); } } public static void OnReceiveConfigSyncRequest(ulong clientId, FastBufferReader reader) { //IL_0048: 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_0065: Unknown result type (might be due to invalid IL or missing references) if (NetworkManager.Singleton.IsServer) { Plugin.Log("Receiving hotbar size sync request from client with id: " + clientId + ". Sending config sync to client."); FastBufferWriter val = default(FastBufferWriter); ((FastBufferWriter)(ref val))..ctor(4, (Allocator)2, -1); ((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref instance.hotbarSize, default(ForPrimitives)); NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("HotbarPlusOnReceiveConfigSync", clientId, val, (NetworkDelivery)3); } } public static void OnReceiveConfigSync(ulong clientId, FastBufferReader reader) { //IL_0012: 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) Plugin.Log("Receiving hotbar size sync from server."); int num = default(int); ((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num, default(ForPrimitives)); instance.hotbarSize = num; OnLocalClientConfigSync(); } public static void OnLocalClientConfigSync() { isSynced = true; PlayerPatcher.ResizeInventory(); HUDPatcher.ResizeHotbarSlotsHUD(); Keybinds.OnSetHotbarSize(); } } }
plugins/FlipMods-LetMeLookDown/LetMeLookDown.dll
Decompiled 10 months agousing System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using GameNetcodeStuff; using HarmonyLib; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("LetMeLookDown")] [assembly: AssemblyDescription("Mod made by flipf17")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("LetMeLookDown")] [assembly: AssemblyCopyright("Copyright © 2023")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("a9c88d54-8f01-44a7-be0d-bd61d38aadcb")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("1.0.0.0")] namespace LetMeLookDown { [BepInPlugin("FlipMods.LetMeLookDown", "LetMeLookDown", "1.0.1")] public class Plugin : BaseUnityPlugin { private Harmony _harmony; private static Plugin instance; public static float maxAngle = 80f; private void Awake() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown _harmony = new Harmony("LetMeLookDown"); _harmony.PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"LetMeLookDown mod loaded"); instance = this; } public static void Log(string message) { ((BaseUnityPlugin)instance).Logger.LogInfo((object)message); } } public static class PluginInfo { public const string PLUGIN_GUID = "FlipMods.LetMeLookDown"; public const string PLUGIN_NAME = "LetMeLookDown"; public const string PLUGIN_VERSION = "1.0.1"; } } namespace LetMeLookDown.Patches { [HarmonyPatch] internal class AdjustSmoothLookingPatcher { [HarmonyPatch(typeof(PlayerControllerB), "CalculateSmoothLookingInput")] private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { List<CodeInstruction> list = new List<CodeInstruction>(instructions); for (int i = 0; i < list.Count; i++) { if (list[i].opcode == OpCodes.Ldc_R4 && (float)list[i].operand == 60f) { list[i].operand = Plugin.maxAngle; break; } } return list.AsEnumerable(); } } [HarmonyPatch] internal class AdjustNormalLookingPatcher { [HarmonyPatch(typeof(PlayerControllerB), "CalculateNormalLookingInput")] private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { List<CodeInstruction> list = new List<CodeInstruction>(instructions); for (int i = 0; i < list.Count; i++) { if (list[i].opcode == OpCodes.Ldc_R4 && (float)list[i].operand == 60f) { list[i].operand = Plugin.maxAngle; break; } } return list.AsEnumerable(); } } }
plugins/FlipMods-ReservedFlashlightSlot/ReservedFlashlightSlot.dll
Decompiled 10 months agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using GameNetcodeStuff; using HarmonyLib; using LethalCompanyInputUtils.Api; using ReservedFlashlightSlot.Patches; using ReservedItemSlotCore; using ReservedItemSlotCore.Networking; using ReservedItemSlotCore.Patches; using Unity.Netcode; using UnityEngine; using UnityEngine.InputSystem; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("ReservedFlashlightSlot")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("ReservedFlashlightSlot")] [assembly: AssemblyCopyright("Copyright © 2023")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("5b7d6563-4e51-4a69-bcf9-fa1dea6eff75")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("1.0.0.0")] namespace ReservedFlashlightSlot { public static class ConfigSettings { public static ConfigEntry<string> activateFlashlightKey; public static ConfigEntry<bool> hideFlashlightMeshShoulder; public static string activateFlashlightDisplayName; public static Dictionary<string, ConfigEntryBase> currentConfigEntries = new Dictionary<string, ConfigEntryBase>(); public static void BindConfigSettings() { Plugin.Log("BindingConfigs"); activateFlashlightKey = ((BaseUnityPlugin)Plugin.instance).Config.Bind<string>("ReservedFlashlightSlot", "ActivateFlashlightKey", "<Keyboard>/f", "This setting will be ignored if InputUtils is installed and enabled. (I recommend running InputUtils to edit keybinds in the in-game settings)"); hideFlashlightMeshShoulder = ((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("ReservedFlashlightSlot", "HideFlashlightOnShoulder", false, "Hides the flashlight mesh while on your shoulder. Only applies in scenarios where you can view your player in third person."); activateFlashlightDisplayName = GetDisplayName(activateFlashlightKey.Value); currentConfigEntries.Add(((ConfigEntryBase)activateFlashlightKey).Definition.Key, (ConfigEntryBase)(object)activateFlashlightKey); currentConfigEntries.Add(((ConfigEntryBase)hideFlashlightMeshShoulder).Definition.Key, (ConfigEntryBase)(object)hideFlashlightMeshShoulder); TryRemoveOldConfigSettings(); } public static string GetDisplayName(string key) { key = key.Replace("<Keyboard>/", ""); key = key.Replace("<Mouse>/", ""); string text = key; text = text.Replace("leftAlt", "Alt"); text = text.Replace("rightAlt", "Alt"); text = text.Replace("leftCtrl", "Ctrl"); text = text.Replace("rightCtrl", "Ctrl"); text = text.Replace("leftShift", "Shift"); text = text.Replace("rightShift", "Shift"); text = text.Replace("leftButton", "LMB"); text = text.Replace("rightButton", "RMB"); return text.Replace("middleButton", "MMB"); } public static void TryRemoveOldConfigSettings() { HashSet<string> hashSet = new HashSet<string>(); HashSet<string> hashSet2 = new HashSet<string>(); foreach (ConfigEntryBase value in currentConfigEntries.Values) { hashSet.Add(value.Definition.Section); hashSet2.Add(value.Definition.Key); } try { Plugin.Log("Cleaning old config entries"); ConfigFile config = ((BaseUnityPlugin)Plugin.instance).Config; string configFilePath = config.ConfigFilePath; if (!File.Exists(configFilePath)) { return; } string text = File.ReadAllText(configFilePath); string[] array = File.ReadAllLines(configFilePath); string text2 = ""; for (int i = 0; i < array.Length; i++) { array[i] = array[i].Replace("\n", ""); if (array[i].Length <= 0) { continue; } if (array[i].StartsWith("[")) { if (text2 != "" && !hashSet.Contains(text2)) { text2 = "[" + text2 + "]"; int num = text.IndexOf(text2); int num2 = text.IndexOf(array[i]); text = text.Remove(num, num2 - num); } text2 = array[i].Replace("[", "").Replace("]", "").Trim(); } else { if (!(text2 != "")) { continue; } if (i <= array.Length - 4 && array[i].StartsWith("##")) { int j; for (j = 1; i + j < array.Length && array[i + j].Length > 3; j++) { } if (hashSet.Contains(text2)) { int num3 = array[i + j - 1].IndexOf("="); string item = array[i + j - 1].Substring(0, num3 - 1); if (!hashSet2.Contains(item)) { int num4 = text.IndexOf(array[i]); int num5 = text.IndexOf(array[i + j - 1]) + array[i + j - 1].Length; text = text.Remove(num4, num5 - num4); } } i += j - 1; } else if (array[i].Length > 3) { text = text.Replace(array[i], ""); } } } if (!hashSet.Contains(text2)) { text2 = "[" + text2 + "]"; int num6 = text.IndexOf(text2); text = text.Remove(num6, text.Length - num6); } while (text.Contains("\n\n\n")) { text = text.Replace("\n\n\n", "\n\n"); } File.WriteAllText(configFilePath, text); config.Reload(); } catch { } } } [BepInPlugin("FlipMods.ReservedFlashlightSlot", "ReservedFlashlightSlot", "1.6.3")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] internal class Plugin : BaseUnityPlugin { public static Plugin instance; private Harmony _harmony; private static ManualLogSource logger; public static ReservedItemInfo proFlashlightInfo = new ReservedItemInfo("Pro-flashlight", 120, false, false, false, false); public static ReservedItemInfo flashlightInfo = new ReservedItemInfo("Flashlight", 120, false, false, false, false); public static ReservedItemInfo laserPointerInfo = new ReservedItemInfo("Laser pointer", 120, false, false, false, false); private void Awake() { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Expected O, but got Unknown instance = this; CreateCustomLogger(); ConfigSettings.BindConfigSettings(); _harmony = new Harmony("ReservedFlashlightSlot"); PatchAll(); Log("ReservedFlashlightSlot loaded"); } private void PatchAll() { IEnumerable<Type> enumerable; try { enumerable = Assembly.GetExecutingAssembly().GetTypes(); } catch (ReflectionTypeLoadException ex) { enumerable = ex.Types.Where((Type t) => t != null); } foreach (Type item in enumerable) { _harmony.PatchAll(item); } } private void CreateCustomLogger() { try { logger = Logger.CreateLogSource($"{((BaseUnityPlugin)this).Info.Metadata.Name}-{((BaseUnityPlugin)this).Info.Metadata.Version}"); } catch { logger = ((BaseUnityPlugin)this).Logger; } } public static void Log(string message) { logger.LogInfo((object)message); } public static void LogError(string message) { logger.LogError((object)message); } public static void LogWarning(string message) { logger.LogWarning((object)message); } public static bool IsModLoaded(string guid) { return Chainloader.PluginInfos.ContainsKey(guid); } } public static class PluginInfo { public const string PLUGIN_GUID = "FlipMods.ReservedFlashlightSlot"; public const string PLUGIN_NAME = "ReservedFlashlightSlot"; public const string PLUGIN_VERSION = "1.6.3"; } } namespace ReservedFlashlightSlot.Patches { [HarmonyPatch] public class MaskedEnemyPatcher { public static Dictionary<MaskedPlayerEnemy, GameObject> heldFlashlightsByEnemy = new Dictionary<MaskedPlayerEnemy, GameObject>(); public static HashSet<MaskedPlayerEnemy> spawnedEnemies = new HashSet<MaskedPlayerEnemy>(); [HarmonyPatch(typeof(MaskedPlayerEnemy), "OnDestroy")] [HarmonyPrefix] public static void OnDestroy(MaskedPlayerEnemy __instance) { if (heldFlashlightsByEnemy.TryGetValue(__instance, out var value)) { Plugin.LogWarning("Destroying flashlight. Enemy destroyed."); Object.DestroyImmediate((Object)(object)value); spawnedEnemies.Remove(__instance); } heldFlashlightsByEnemy.Remove(__instance); } [HarmonyPatch(typeof(MaskedPlayerEnemy), "LateUpdate")] [HarmonyPostfix] public static void ShowWalkieOnEnemy(MaskedPlayerEnemy __instance) { //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Expected O, but got Unknown //IL_020b: Unknown result type (might be due to invalid IL or missing references) //IL_0210: Unknown result type (might be due to invalid IL or missing references) //IL_0215: Unknown result type (might be due to invalid IL or missing references) //IL_021a: Unknown result type (might be due to invalid IL or missing references) //IL_022d: Unknown result type (might be due to invalid IL or missing references) //IL_0234: Unknown result type (might be due to invalid IL or missing references) //IL_0239: Unknown result type (might be due to invalid IL or missing references) //IL_023e: Unknown result type (might be due to invalid IL or missing references) //IL_0243: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: 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_013c: Unknown result type (might be due to invalid IL or missing references) //IL_0148: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) if (!spawnedEnemies.Contains(__instance) && SyncManager.syncReservedItemsList.Contains(Plugin.proFlashlightInfo) && !((EnemyAI)__instance).isEnemyDead && !heldFlashlightsByEnemy.ContainsKey(__instance) && (Object)(object)__instance.mimickingPlayer != (Object)null && PlayerPatcher.allPlayerData.TryGetValue(__instance.mimickingPlayer, out var value)) { spawnedEnemies.Add(__instance); FlashlightItem reservedFlashlight = FlashlightPatcher.GetReservedFlashlight(value.playerController); if ((Object)(object)reservedFlashlight != (Object)null) { Plugin.LogWarning("OnMaskedEnemySpawn - MimickingPlayer: " + ((Object)value.playerController).name + " - Spawning flashlight object on enemy."); GameObject val = new GameObject("ReservedFlashlight [MaskedEnemy]"); Light[] componentsInChildren = ((Component)reservedFlashlight).GetComponentsInChildren<Light>(); MeshRenderer mainObjectRenderer = ((GrabbableObject)reservedFlashlight).mainObjectRenderer; Light[] array = componentsInChildren; foreach (Light val2 in array) { Light component = Object.Instantiate<GameObject>(((Component)val2).gameObject, ((Component)val2).transform.localPosition, ((Component)val2).transform.localRotation, val.transform).GetComponent<Light>(); ((Behaviour)component).enabled = true; ((Component)component).gameObject.layer = 6; } MeshRenderer component2 = Object.Instantiate<GameObject>(((Component)mainObjectRenderer).gameObject, ((Component)mainObjectRenderer).transform.localPosition, ((Component)mainObjectRenderer).transform.localRotation, val.transform).GetComponent<MeshRenderer>(); ((Renderer)component2).enabled = true; ((Component)component2).gameObject.layer = 6; val.transform.localScale = ((Component)reservedFlashlight).transform.localScale; heldFlashlightsByEnemy.Add(__instance, val); } } if (heldFlashlightsByEnemy.TryGetValue(__instance, out var value2)) { if (((EnemyAI)__instance).isEnemyDead) { Plugin.LogWarning("Destroying flashlight. Enemy dead."); Object.DestroyImmediate((Object)(object)value2); spawnedEnemies.Remove(__instance); heldFlashlightsByEnemy.Remove(__instance); } else { Transform parent = ((EnemyAI)__instance).eye.parent.parent; value2.transform.rotation = parent.rotation * Quaternion.Euler(FlashlightPatcher.playerShoulderRotationOffset); value2.transform.position = parent.position + parent.rotation * FlashlightPatcher.playerShoulderPositionOffset; } } } } [HarmonyPatch] internal static class FlashlightPatcher { public static Vector3 playerShoulderPositionOffset = new Vector3(0.2f, 0.25f, 0f); public static Vector3 playerShoulderRotationOffset = new Vector3(90f, 0f, 0f); public static PlayerControllerB localPlayerController => PlayerPatcher.localPlayerController; public static PlayerControllerB GetPreviousPlayerHeldBy(FlashlightItem flashlightItem) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown return (PlayerControllerB)Traverse.Create((object)flashlightItem).Field("previousPlayerHeldBy").GetValue(); } public static FlashlightItem GetMainFlashlight(PlayerControllerB playerController) { return GetCurrentlySelectedFlashlight(playerController) ?? GetReservedFlashlight(playerController); } public static FlashlightItem GetReservedFlashlight(PlayerControllerB playerController) { ReservedPlayerData value; return (FlashlightItem)((SyncManager.syncReservedItemsList.Contains(Plugin.flashlightInfo) && PlayerPatcher.allPlayerData.TryGetValue(playerController, out value)) ? /*isinst with value type is only supported in some contexts*/: null); } public static FlashlightItem GetCurrentlySelectedFlashlight(PlayerControllerB playerController) { return (FlashlightItem)((playerController.currentItemSlot >= 0 && playerController.currentItemSlot < playerController.ItemSlots.Length) ? /*isinst with value type is only supported in some contexts*/: null); } public static bool IsFlashlightOn(PlayerControllerB playerController) { return ((GrabbableObject)(GetMainFlashlight(playerController)?)).isBeingUsed ?? false; } [HarmonyPatch(typeof(FlashlightItem), "SwitchFlashlight")] [HarmonyPostfix] public static void OnSwitchOnOffFlashlight(bool on, FlashlightItem __instance) { if (!((Object)(object)((GrabbableObject)__instance).playerHeldBy == (Object)null)) { UpdateAllFlashlightStates(((GrabbableObject)__instance).playerHeldBy, on); } } [HarmonyPatch(typeof(FlashlightItem), "PocketItem")] [HarmonyPostfix] public static void OnPocketFlashlightLocal(FlashlightItem __instance) { OnPocketFlashlight(__instance, ((GrabbableObject)__instance).isBeingUsed); } [HarmonyPatch(typeof(FlashlightItem), "PocketFlashlightClientRpc")] [HarmonyPrefix] public static void OnPocketFlashlightClientRpc(bool stillUsingFlashlight, FlashlightItem __instance) { if (NetworkHelper.IsValidClientRpcExecStage((NetworkBehaviour)(object)__instance) && !((NetworkBehaviour)__instance).IsOwner && !((Object)(object)((GrabbableObject)__instance).playerHeldBy == (Object)null) && !((Object)(object)((GrabbableObject)__instance).playerHeldBy == (Object)(object)localPlayerController)) { OnPocketFlashlight(__instance, stillUsingFlashlight); } } private static void OnPocketFlashlight(FlashlightItem flashlightItem, bool stillUsingFlashlight = false) { if ((Object)(object)((GrabbableObject)flashlightItem).playerHeldBy == (Object)null) { return; } FlashlightItem currentlySelectedFlashlight = GetCurrentlySelectedFlashlight(((GrabbableObject)flashlightItem).playerHeldBy); FlashlightItem reservedFlashlight = GetReservedFlashlight(((GrabbableObject)flashlightItem).playerHeldBy); bool flag = stillUsingFlashlight || ((Object)(object)currentlySelectedFlashlight != (Object)null && ((GrabbableObject)currentlySelectedFlashlight).isBeingUsed); if ((Object)(object)currentlySelectedFlashlight != (Object)null && ((GrabbableObject)currentlySelectedFlashlight).isBeingUsed) { ((GrabbableObject)flashlightItem).playerHeldBy.pocketedFlashlight = null; } else if (((GrabbableObject)flashlightItem).isBeingUsed) { ((GrabbableObject)flashlightItem).playerHeldBy.pocketedFlashlight = (GrabbableObject)(object)flashlightItem; } else if ((Object)(object)reservedFlashlight != (Object)null && ((Object)(object)((GrabbableObject)flashlightItem).playerHeldBy.pocketedFlashlight == (Object)null || !((GrabbableObject)flashlightItem).playerHeldBy.pocketedFlashlight.isBeingUsed)) { ((GrabbableObject)flashlightItem).playerHeldBy.pocketedFlashlight = (GrabbableObject)(object)reservedFlashlight; } MeshRenderer[] componentsInChildren = ((Component)flashlightItem).GetComponentsInChildren<MeshRenderer>(); foreach (MeshRenderer val in componentsInChildren) { if (!((Object)val).name.Contains("ScanNode") && !((Component)val).gameObject.CompareTag("DoNotSet") && !((Component)val).gameObject.CompareTag("InteractTrigger")) { ((Component)val).gameObject.layer = (((Object)(object)((GrabbableObject)flashlightItem).playerHeldBy == (Object)(object)localPlayerController) ? 23 : 6); } } if ((Object)(object)flashlightItem == (Object)(object)reservedFlashlight) { ((GrabbableObject)flashlightItem).parentObject = ((GrabbableObject)flashlightItem).playerHeldBy.playerGlobalHead.parent; } } [HarmonyPatch(typeof(FlashlightItem), "EquipItem")] [HarmonyPostfix] public static void OnEquipFlashlight(FlashlightItem __instance) { if ((Object)(object)((GrabbableObject)__instance).playerHeldBy == (Object)null) { return; } bool mainFlashlightActive = ((Object)(object)((GrabbableObject)__instance).playerHeldBy.pocketedFlashlight != (Object)null && ((GrabbableObject)__instance).playerHeldBy.pocketedFlashlight.isBeingUsed) || ((GrabbableObject)__instance).isBeingUsed; FlashlightItem reservedFlashlight = GetReservedFlashlight(((GrabbableObject)__instance).playerHeldBy); if (((GrabbableObject)__instance).isBeingUsed || (Object)(object)__instance == (Object)(object)((GrabbableObject)__instance).playerHeldBy.pocketedFlashlight) { ((GrabbableObject)__instance).playerHeldBy.pocketedFlashlight = null; } else if ((Object)(object)reservedFlashlight != (Object)null && ((Object)(object)((GrabbableObject)__instance).playerHeldBy.pocketedFlashlight == (Object)null || !((GrabbableObject)__instance).playerHeldBy.pocketedFlashlight.isBeingUsed)) { ((GrabbableObject)__instance).playerHeldBy.pocketedFlashlight = (GrabbableObject)(object)reservedFlashlight; } MeshRenderer[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<MeshRenderer>(); foreach (MeshRenderer val in componentsInChildren) { if (!((Object)val).name.Contains("ScanNode") && !((Component)val).gameObject.CompareTag("DoNotSet") && !((Component)val).gameObject.CompareTag("InteractTrigger")) { ((Component)val).gameObject.layer = 6; } } ((GrabbableObject)__instance).parentObject = (((Object)(object)((GrabbableObject)__instance).playerHeldBy == (Object)(object)localPlayerController) ? ((GrabbableObject)__instance).playerHeldBy.localItemHolder : ((GrabbableObject)__instance).playerHeldBy.serverItemHolder); UpdateAllFlashlightStates(((GrabbableObject)__instance).playerHeldBy, mainFlashlightActive); } [HarmonyPatch(typeof(FlashlightItem), "DiscardItem")] [HarmonyPrefix] public static void ResetPocketedFlashlight(FlashlightItem __instance) { PlayerControllerB previousPlayerHeldBy = GetPreviousPlayerHeldBy(__instance); if ((Object)(object)previousPlayerHeldBy == (Object)null) { return; } FlashlightItem reservedFlashlight = GetReservedFlashlight(previousPlayerHeldBy); if ((Object)(object)reservedFlashlight != (Object)null && ((Object)(object)__instance == (Object)(object)previousPlayerHeldBy.pocketedFlashlight || (Object)(object)previousPlayerHeldBy.pocketedFlashlight == (Object)null)) { previousPlayerHeldBy.pocketedFlashlight = (GrabbableObject)(object)reservedFlashlight; } MeshRenderer[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<MeshRenderer>(); foreach (MeshRenderer val in componentsInChildren) { if (!((Object)val).name.Contains("ScanNode") && !((Component)val).gameObject.CompareTag("DoNotSet") && !((Component)val).gameObject.CompareTag("InteractTrigger")) { ((Component)val).gameObject.layer = 6; } } } [HarmonyPatch(typeof(GrabbableObject), "LateUpdate")] [HarmonyPostfix] public static void SetPositionOffset(GrabbableObject __instance) { //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_009d: 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_00ac: Unknown result type (might be due to invalid IL or missing references) if (__instance is FlashlightItem && (Object)(object)__instance.playerHeldBy != (Object)null && (Object)(object)__instance.parentObject != (Object)null && __instance.isPocketed && (Object)(object)__instance == (Object)(object)GetReservedFlashlight(__instance.playerHeldBy) && (Object)(object)__instance != (Object)(object)GetCurrentlySelectedFlashlight(__instance.playerHeldBy)) { Transform transform = ((Component)__instance.parentObject).transform; ((Component)__instance).transform.rotation = ((Component)__instance.parentObject).transform.rotation * Quaternion.Euler(playerShoulderRotationOffset); ((Component)__instance).transform.position = transform.position + transform.rotation * playerShoulderPositionOffset; } } [HarmonyPatch(typeof(GrabbableObject), "EnableItemMeshes")] [HarmonyPrefix] public static void OnEnableItemMeshes(ref bool enable, GrabbableObject __instance) { if (__instance is FlashlightItem && (Object)(object)__instance.playerHeldBy != (Object)null && (Object)(object)__instance == (Object)(object)GetReservedFlashlight(__instance.playerHeldBy) && !ConfigSettings.hideFlashlightMeshShoulder.Value && !ReservedItemPatcher.ReservedItemIsBeingGrabbed(__instance)) { enable = true; } } private static void UpdateAllFlashlightStates(PlayerControllerB playerController, bool mainFlashlightActive = true) { FlashlightItem mainFlashlight = GetMainFlashlight(playerController); if ((Object)(object)mainFlashlight == (Object)null) { ((Behaviour)playerController.helmetLight).enabled = false; mainFlashlightActive = false; } else { playerController.ChangeHelmetLight(mainFlashlight.flashlightTypeID, mainFlashlightActive && (Object)(object)playerController == (Object)(object)localPlayerController && (Object)(object)playerController.ItemSlots[playerController.currentItemSlot] != (Object)(object)mainFlashlight); } for (int i = 0; i < playerController.ItemSlots.Length; i++) { GrabbableObject obj = playerController.ItemSlots[i]; FlashlightItem val = (FlashlightItem)(object)((obj is FlashlightItem) ? obj : null); if ((Object)(object)val != (Object)null) { UpdateFlashlightState(val, (Object)(object)val == (Object)(object)mainFlashlight && mainFlashlightActive); } } } private static void UpdateFlashlightState(FlashlightItem flashlightItem, bool active) { if (!((Object)(object)((GrabbableObject)flashlightItem).playerHeldBy == (Object)null)) { PlayerControllerB playerHeldBy = ((GrabbableObject)flashlightItem).playerHeldBy; ((GrabbableObject)flashlightItem).isBeingUsed = active; bool flag = (Object)(object)playerHeldBy != (Object)(object)localPlayerController || (Object)(object)playerHeldBy.ItemSlots[playerHeldBy.currentItemSlot] == (Object)(object)flashlightItem; ((Behaviour)flashlightItem.flashlightBulb).enabled = active && flag; ((Behaviour)flashlightItem.flashlightBulbGlow).enabled = active && flag; flashlightItem.usingPlayerHelmetLight = active && !flag; } } } } namespace ReservedFlashlightSlot.Input { internal class InputUtilsCompat { internal static InputActionAsset Asset => IngameKeybinds.GetAsset(); internal static bool Enabled => Plugin.IsModLoaded("com.rune580.LethalCompanyInputUtils"); public static InputAction ToggleFlashlightHotkey => IngameKeybinds.Instance.ToggleFlashlightHotkey; } internal class IngameKeybinds : LcInputActions { internal static IngameKeybinds Instance = new IngameKeybinds(); [InputAction("<Keyboard>/f", Name = "[ReservedItemSlots]\nToggle flashlight")] public InputAction ToggleFlashlightHotkey { get; set; } internal static InputActionAsset GetAsset() { return ((LcInputActions)Instance).Asset; } } [HarmonyPatch] internal static class Keybinds { public static InputActionAsset Asset; public static InputActionMap ActionMap; private static InputAction ActivateFlashlightAction; public static PlayerControllerB localPlayerController => StartOfRound.Instance?.localPlayerController; [HarmonyPatch(typeof(PreInitSceneScript), "Awake")] [HarmonyPrefix] public static void AddToKeybindMenu() { //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Expected O, but got Unknown //IL_0025: 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) Plugin.Log("Initializing hotkeys."); if (InputUtilsCompat.Enabled) { Asset = InputUtilsCompat.Asset; ActionMap = Asset.actionMaps[0]; ActivateFlashlightAction = InputUtilsCompat.ToggleFlashlightHotkey; } else { Asset = ScriptableObject.CreateInstance<InputActionAsset>(); ActionMap = new InputActionMap("ReservedItemSlots"); InputActionSetupExtensions.AddActionMap(Asset, ActionMap); ActivateFlashlightAction = InputActionSetupExtensions.AddAction(ActionMap, "ReservedItemSlots.ToggleFlashlight", (InputActionType)0, ConfigSettings.activateFlashlightKey.Value, (string)null, (string)null, (string)null, (string)null); } } [HarmonyPatch(typeof(StartOfRound), "OnEnable")] [HarmonyPostfix] public static void OnEnable() { Asset.Enable(); ActivateFlashlightAction.performed += OnActivateFlashlightPerformed; } [HarmonyPatch(typeof(StartOfRound), "OnDisable")] [HarmonyPostfix] public static void OnDisable() { Asset.Disable(); ActivateFlashlightAction.performed -= OnActivateFlashlightPerformed; } private static void OnActivateFlashlightPerformed(CallbackContext context) { if ((Object)(object)localPlayerController == (Object)null || !localPlayerController.isPlayerControlled || (((NetworkBehaviour)localPlayerController).IsServer && !localPlayerController.isHostPlayerObject)) { return; } FlashlightItem mainFlashlight = FlashlightPatcher.GetMainFlashlight(localPlayerController); if (((CallbackContext)(ref context)).performed && !((Object)(object)mainFlashlight == (Object)null) && !ShipBuildModeManager.Instance.InBuildMode && !localPlayerController.inTerminalMenu) { float num = (float)Traverse.Create((object)localPlayerController).Field("timeSinceSwitchingSlots").GetValue(); if (!(num < 0.075f)) { ((GrabbableObject)mainFlashlight).UseItemOnClient(!((GrabbableObject)mainFlashlight).isBeingUsed); Traverse.Create((object)localPlayerController).Field("timeSinceSwitchingSlots").SetValue((object)0); } } } } }
plugins/FlipMods-ReservedItemSlotCore/ReservedItemSlotCore.dll
Decompiled 10 months agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using GameNetcodeStuff; using HarmonyLib; using LethalCompanyInputUtils.Api; using ReservedItemSlotCore.Compatibility; using ReservedItemSlotCore.Config; using ReservedItemSlotCore.Input; using ReservedItemSlotCore.Networking; using ReservedItemSlotCore.Patches; using TMPro; using Unity.Collections; using Unity.Netcode; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("ReservedItemSlotCore")] [assembly: AssemblyDescription("Mod made by flipf17")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("ReservedItemSlotCore")] [assembly: AssemblyCopyright("Copyright © 2023")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("238ce080-e339-46b6-9b08-992a950453a1")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: InternalsVisibleTo("ReservedFlashlightSlot")] [assembly: InternalsVisibleTo("ReservedWalkieSlot")] [assembly: InternalsVisibleTo("ReservedWeaponSlot")] [assembly: InternalsVisibleTo("ReservedSprayPaintSlot")] [assembly: InternalsVisibleTo("ReservedBoomboxSlot")] [assembly: InternalsVisibleTo("ReservedUtilitySlot")] [assembly: InternalsVisibleTo("ReservedPersonalBoomboxSlot")] [assembly: InternalsVisibleTo("ReservedKeySlot")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("1.0.0.0")] namespace ReservedItemSlotCore { internal class ReservedItemInfo { public static Dictionary<string, ReservedItemInfo> reservedItemsDictDefault = new Dictionary<string, ReservedItemInfo>(); public static List<ReservedItemInfo> reservedItemsListDefault = new List<ReservedItemInfo>(); public static List<ReservedItemInfo> reservedItemSlotRepsDefault = new List<ReservedItemInfo>(); public static Dictionary<string, ReservedItemInfo> reservedItemsDict = new Dictionary<string, ReservedItemInfo>(); public static List<ReservedItemInfo> reservedItemsList = new List<ReservedItemInfo>(); public static List<ReservedItemInfo> reservedItemSlotReps = new List<ReservedItemInfo>(); public string itemName = ""; public HashSet<string> acceptedItemNames; public int hotbarSlotPriority = 0; public int reservedItemIndex = 0; public bool forceUpdateCanBeGrabbedBeforeGameStart = false; public bool canBeGrabbedBeforeGameStart = false; public bool forceUpdateRequiresBattery = false; public bool requiresBattery = false; public static int numReservedItemSlotsDefault => reservedItemSlotRepsDefault.Count; public ReservedItemInfo() { } public ReservedItemInfo(string itemName, int hotbarSlotPriority, bool forceUpdateCanBeGrabbedBeforeGameStart = false, bool canBeGrabbedBeforeGameStart = false, bool forceUpdateRequiresBattery = false, bool requiresBattery = false) { this.itemName = itemName; this.hotbarSlotPriority = hotbarSlotPriority; AddItemInfoToList(this); ReservedItemInfo info = new ReservedItemInfo(this); AddItemInfoToList(info, reservedItemsListDefault, reservedItemsDictDefault, reservedItemSlotRepsDefault); } public static void AddItemInfoToList(ReservedItemInfo info, List<ReservedItemInfo> _reservedItemsList = null, Dictionary<string, ReservedItemInfo> _reservedItemsDict = null, List<ReservedItemInfo> _reservedItemSlotReps = null) { if (_reservedItemsList == null) { _reservedItemsList = reservedItemsList; } if (_reservedItemsDict == null) { _reservedItemsDict = reservedItemsDict; } if (_reservedItemSlotReps == null) { _reservedItemSlotReps = reservedItemSlotReps; } if (!_reservedItemsDict.ContainsKey(info.itemName)) { _reservedItemsDict.Add(info.itemName, info); _reservedItemsList.Add(info); int i; for (i = 0; i < _reservedItemSlotReps.Count; i++) { ReservedItemInfo reservedItemInfo = _reservedItemSlotReps[i]; if (info.hotbarSlotPriority >= reservedItemInfo.hotbarSlotPriority) { break; } } info.reservedItemIndex = i; if (i == _reservedItemSlotReps.Count || info.hotbarSlotPriority != _reservedItemSlotReps[i].hotbarSlotPriority) { info.acceptedItemNames = new HashSet<string> { info.itemName }; _reservedItemSlotReps.Insert(i, info); { foreach (ReservedItemInfo _reservedItems in _reservedItemsList) { if (info != _reservedItems && _reservedItems.reservedItemIndex >= i) { _reservedItems.reservedItemIndex++; } } return; } } info.acceptedItemNames = _reservedItemSlotReps[i].acceptedItemNames; info.acceptedItemNames.Add(info.itemName); } else { Plugin.Log($"Tried to add duplicate item name to the ReservedItems list: {info.itemName}. Sorting instead"); } } public ReservedItemInfo(ReservedItemInfo copyFrom) { itemName = copyFrom.itemName; hotbarSlotPriority = copyFrom.hotbarSlotPriority; reservedItemIndex = copyFrom.reservedItemIndex; forceUpdateCanBeGrabbedBeforeGameStart = copyFrom.forceUpdateCanBeGrabbedBeforeGameStart; canBeGrabbedBeforeGameStart = copyFrom.canBeGrabbedBeforeGameStart; forceUpdateRequiresBattery = copyFrom.forceUpdateRequiresBattery; requiresBattery = copyFrom.requiresBattery; } } internal class ReservedPlayerData { public PlayerControllerB playerController; public ReservedItemInfo grabbingReservedItemInfo = null; public GrabbableObject grabbingReservedItem = null; public int previousHotbarIndex = -1; public bool inReservedHotbarSlots = false; public int hotbarSize = 4; public int reservedHotbarStartIndex = 4; public bool isLocalPlayer => (Object)(object)playerController != (Object)null && (Object)(object)playerController == (Object)(object)StartOfRound.Instance?.localPlayerController; public int currentItemSlot => playerController.currentItemSlot; public bool currentItemSlotIsReserved => currentItemSlot >= reservedHotbarStartIndex && currentItemSlot < reservedHotbarStartIndex + SyncManager.numReservedItemSlots; public GrabbableObject previouslyHeldItem => (previousHotbarIndex >= 0 && previousHotbarIndex < playerController.ItemSlots.Length) ? playerController.ItemSlots[previousHotbarIndex] : null; public bool throwingObject => (bool)Traverse.Create((object)playerController).Field("throwingObject").GetValue(); public int reservedHotbarEndIndexExcluded => reservedHotbarStartIndex + SyncManager.numReservedItemSlots; public bool IsReservedItemSlot(int index) { return index >= reservedHotbarStartIndex && index < reservedHotbarStartIndex + SyncManager.numReservedItemSlots; } public int GetNumHeldReservedItems() { int num = 0; for (int i = 0; i < playerController.ItemSlots.Length; i++) { GrabbableObject val = playerController.ItemSlots[i]; num += (((Object)(object)val != (Object)null && SyncManager.IsReservedItem(val.itemProperties.itemName)) ? 1 : 0); } return num; } public GrabbableObject GetReservedItem(ReservedItemInfo itemInfo) { if (itemInfo == null) { return null; } int num = reservedHotbarStartIndex + itemInfo.reservedItemIndex; return (num >= 0 && num < playerController.ItemSlots.Length) ? playerController.ItemSlots[num] : null; } public string DumpData() { if ((Object)(object)playerController == (Object)null) { Plugin.LogError("PLAYER NULL"); } if (SyncManager.syncReservedItemSlotReps == null) { Plugin.LogError("REPS NULL"); } string text = "[ReservedPlayerData Dump]\nPlayer: " + ((Object)playerController).name + (isLocalPlayer ? " [LocalPlayer]" : "") + "\nCurrentItemSlot: " + currentItemSlot + "\nRegisteredHotbarSize: " + hotbarSize + "\nActualHotbarSize: " + playerController.ItemSlots.Length + "\nCurrentlyGrabbingReservedItem: " + ((grabbingReservedItemInfo != null) ? grabbingReservedItemInfo.itemName : "false") + "\nReservedHotbarStartIndex: " + reservedHotbarStartIndex + "\n" + (isLocalPlayer ? ("NumItemSlotsHUD: " + HUDManager.Instance.itemSlotIconFrames.Length + "\n") : "") + "ItemsInInventory: ["; for (int i = 0; i < playerController.ItemSlots.Length; i++) { if (i > 0) { text += ", "; } text += (("[" + i + "] " + (object)playerController.ItemSlots[i] != null) ? ((Object)playerController.ItemSlots[i]).name : "Empty"); } return text + "]\nNumHeldReservedItems: " + GetNumHeldReservedItems(); } } [BepInPlugin("FlipMods.ReservedItemSlotCore", "ReservedItemSlotCore", "1.8.17")] [BepInDependency(/*Could not decode attribute arguments.*/)] internal class Plugin : BaseUnityPlugin { private Harmony _harmony; public static Plugin instance; private static ManualLogSource logger; public static Dictionary<string, ReservedItemInfo> reservedItemsDictDefault => ReservedItemInfo.reservedItemsDictDefault; public static List<ReservedItemInfo> reservedItemsListDefault => ReservedItemInfo.reservedItemsListDefault; public static List<ReservedItemInfo> reservedItemSlotRepsDefault => ReservedItemInfo.reservedItemSlotRepsDefault; public static int numReservedItemSlotsDefault => ReservedItemInfo.numReservedItemSlotsDefault; private void Awake() { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Expected O, but got Unknown instance = this; CreateCustomLogger(); ConfigSettings.BindConfigSettings(); if (InputUtilsCompat.Enabled) { InputUtilsCompat.Init(); } _harmony = new Harmony("ReservedItemSlotCore"); PatchAll(); Log("ReservedItemSlotCore loaded"); } private void PatchAll() { IEnumerable<Type> enumerable; try { enumerable = Assembly.GetExecutingAssembly().GetTypes(); } catch (ReflectionTypeLoadException ex) { enumerable = ex.Types.Where((Type t) => t != null); } foreach (Type item in enumerable) { _harmony.PatchAll(item); } } private void CreateCustomLogger() { try { logger = Logger.CreateLogSource($"{((BaseUnityPlugin)this).Info.Metadata.Name}-{((BaseUnityPlugin)this).Info.Metadata.Version}"); } catch { logger = ((BaseUnityPlugin)this).Logger; } } public static void Log(string message) { logger.LogInfo((object)message); } public static void LogError(string message) { logger.LogError((object)message); } public static void LogWarning(string message) { logger.LogWarning((object)message); } public static bool IsModLoaded(string guid) { return Chainloader.PluginInfos.ContainsKey(guid); } public static bool IsReservedItemDefault(string itemName) { return reservedItemsDictDefault.ContainsKey(itemName); } public static ReservedItemInfo GetReservedItemInfoDefault(string itemName) { return IsReservedItemDefault(itemName) ? reservedItemsDictDefault[itemName] : null; } public static ReservedItemInfo GetReservedItemInfoDefault(GrabbableObject item) { return ((Object)(object)item != (Object)null) ? GetReservedItemInfoDefault(item.itemProperties.itemName) : null; } } public static class PluginInfo { public const string PLUGIN_GUID = "FlipMods.ReservedItemSlotCore"; public const string PLUGIN_NAME = "ReservedItemSlotCore"; public const string PLUGIN_VERSION = "1.8.17"; } [HarmonyPatch] public static class UpdateKeybindDisplayNames { public static bool usingControllerPrevious; public static bool usingController => StartOfRound.Instance.localPlayerUsingController; [HarmonyPatch(typeof(HUDManager), "Update")] [HarmonyPostfix] public static void CheckForInputSourceUpdate() { if (usingController != usingControllerPrevious) { usingControllerPrevious = usingController; UpdateControlTipLines(); } } [HarmonyPatch(typeof(KepRemapPanel), "OnDisable")] [HarmonyPostfix] public static void OnCloseRemapPanel() { UpdateControlTipLines(); } public static void UpdateControlTipLines() { HUDPatcher.UpdateHotkeyTooltipText(); } } } namespace ReservedItemSlotCore.Config { public static class ConfigSettings { public static ConfigEntry<bool> forceEnableThisModIfNotEnabledOnHost; public static ConfigEntry<bool> displayNegativePrioritySlotsLeftSideOfScreen; public static ConfigEntry<string> focusReservedHotbarHotkey; public static ConfigEntry<bool> toggleFocusReservedHotbar; public static ConfigEntry<bool> preventReservedItemSlotFade; public static Dictionary<string, ConfigEntryBase> currentConfigEntries = new Dictionary<string, ConfigEntryBase>(); public static void BindConfigSettings() { Plugin.Log("BindingConfigs"); forceEnableThisModIfNotEnabledOnHost = AddConfigEntry<bool>(((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("ReservedItemSlotCore", "ForceEnableThisModIfNotEnabledOnHost", false, "This is disabled by default for a reason, and it is NOT recommended to enable this, especially in public lobbies. Enabling this when the host does not have the ReservedItemSlotCore mod CAN, and likely WILL cause de-sync issues. You have been warned. This setting only applies if you are a non-host client, and the host does not have this mod.")); displayNegativePrioritySlotsLeftSideOfScreen = AddConfigEntry<bool>(((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("ReservedItemSlotCore", "DisplayNegativePrioritySlotsLeftSideOfScreen", true, "For any reserved item slot mods that have a negative priority, by default, those slots will appear on the left side of the screen, rather than the right. Setting this option to false will have them appear on top of the slots on the right side.")); focusReservedHotbarHotkey = AddConfigEntry<string>(((BaseUnityPlugin)Plugin.instance).Config.Bind<string>("ReservedItemSlotCore", "FocusReservedItemSlotsHotkey", "<Keyboard>/leftAlt", "This setting will be ignored if InputUtils is installed and enabled. (I recommend running InputUtils to edit keybinds in the in-game settings)")); toggleFocusReservedHotbar = AddConfigEntry<bool>(((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("ReservedItemSlotCore", "ToggleFocusReservedHotbar", false, "If set to true, swapping to the reserved hotbar slots will be toggled when pressing the hotkey rather than while holding the hotkey. Setting this option to true may have bugs at this current time.")); preventReservedItemSlotFade = AddConfigEntry<bool>(((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("ReservedItemSlotCore", "PreventReservedHotbarSlotFade", false, "If true, the reserved hotbar slots will not fade with the rest of the default slots.")); TryRemoveOldConfigSettings(); } public static ConfigEntry<T> AddConfigEntry<T>(ConfigEntry<T> configEntry) { currentConfigEntries.Add(((ConfigEntryBase)configEntry).Definition.Key, (ConfigEntryBase)(object)configEntry); return configEntry; } public static string GetDisplayName(string key) { try { if (key.Length <= 1) { return key; } int num = key.IndexOf(">/"); key = ((num >= 0) ? key.Substring(num + 2) : key); string text = key.ToLower(); if (text.Contains("not-bound")) { return ""; } text = text.Replace("leftalt", "Alt"); text = text.Replace("rightalt", "Alt"); text = text.Replace("leftctrl", "Ctrl"); text = text.Replace("rightctrl", "Ctrl"); text = text.Replace("leftshift", "Shift"); text = text.Replace("rightshift", "Shift"); text = text.Replace("leftbutton", "LMB"); text = text.Replace("rightbutton", "RMB"); text = text.Replace("middlebutton", "MMB"); text = text.Replace("lefttrigger", "LT"); text = text.Replace("righttrigger", "RT"); text = text.Replace("leftshoulder", "LB"); text = text.Replace("rightshoulder", "RB"); text = text.Replace("leftstickpress", "LS"); text = text.Replace("rightstickpress", "RS"); text = text.Replace("dpad/", "DPad-"); text = text.Replace("backquote", "`"); try { text = char.ToUpper(text[0]) + text.Substring(1); } catch { } return text; } catch { return ""; } } public static void TryRemoveOldConfigSettings() { HashSet<string> hashSet = new HashSet<string>(); HashSet<string> hashSet2 = new HashSet<string>(); foreach (ConfigEntryBase value in currentConfigEntries.Values) { hashSet.Add(value.Definition.Section); hashSet2.Add(value.Definition.Key); } try { Plugin.Log("Cleaning old config entries"); ConfigFile config = ((BaseUnityPlugin)Plugin.instance).Config; string configFilePath = config.ConfigFilePath; if (!File.Exists(configFilePath)) { return; } string text = File.ReadAllText(configFilePath); string[] array = File.ReadAllLines(configFilePath); string text2 = ""; for (int i = 0; i < array.Length; i++) { array[i] = array[i].Replace("\n", ""); if (array[i].Length <= 0) { continue; } if (array[i].StartsWith("[")) { if (text2 != "" && !hashSet.Contains(text2)) { text2 = "[" + text2 + "]"; int num = text.IndexOf(text2); int num2 = text.IndexOf(array[i]); text = text.Remove(num, num2 - num); } text2 = array[i].Replace("[", "").Replace("]", "").Trim(); } else { if (!(text2 != "")) { continue; } if (i <= array.Length - 4 && array[i].StartsWith("##")) { int j; for (j = 1; i + j < array.Length && array[i + j].Length > 3; j++) { } if (hashSet.Contains(text2)) { int num3 = array[i + j - 1].IndexOf("="); string item = array[i + j - 1].Substring(0, num3 - 1); if (!hashSet2.Contains(item)) { int num4 = text.IndexOf(array[i]); int num5 = text.IndexOf(array[i + j - 1]) + array[i + j - 1].Length; text = text.Remove(num4, num5 - num4); } } i += j - 1; } else if (array[i].Length > 3) { text = text.Replace(array[i], ""); } } } if (!hashSet.Contains(text2)) { text2 = "[" + text2 + "]"; int num6 = text.IndexOf(text2); text = text.Remove(num6, text.Length - num6); } while (text.Contains("\n\n\n")) { text = text.Replace("\n\n\n", "\n\n"); } File.WriteAllText(configFilePath, text); config.Reload(); } catch { } } } } namespace ReservedItemSlotCore.Networking { public static class NetworkHelper { private static int NONE_EXEC_STAGE = 0; private static int SERVER_EXEC_STAGE = 1; private static int CLIENT_EXEC_STAGE = 2; public static int GetExecStage(NetworkBehaviour __instance) { return (int)Traverse.Create((object)__instance).Field("__rpc_exec_stage").GetValue(); } public static bool IsClientExecStage(NetworkBehaviour __instance) { return GetExecStage(__instance) == CLIENT_EXEC_STAGE; } public static bool IsServerExecStage(NetworkBehaviour __instance) { return GetExecStage(__instance) == SERVER_EXEC_STAGE; } public static bool IsValidClientRpcExecStage(NetworkBehaviour __instance) { NetworkManager singleton = NetworkManager.Singleton; if ((Object)(object)singleton == (Object)null || !singleton.IsListening) { return false; } int num = (int)Traverse.Create((object)__instance).Field("__rpc_exec_stage").GetValue(); if ((singleton.IsServer || singleton.IsHost) && num != 2) { return false; } return true; } } [HarmonyPatch] internal class SyncManager { public static PlayerControllerB localPlayerController; public static bool isSynced = false; public static Dictionary<string, ReservedItemInfo> syncReservedItemsDict = new Dictionary<string, ReservedItemInfo>(); public static List<ReservedItemInfo> syncReservedItemsList = new List<ReservedItemInfo>(); public static List<ReservedItemInfo> syncReservedItemSlotReps = new List<ReservedItemInfo>(); public static bool canUseModDisabledOnHost => ConfigSettings.forceEnableThisModIfNotEnabledOnHost.Value; public static int numReservedItemSlots => syncReservedItemSlotReps.Count; public static bool IsReservedItem(string itemName) { return syncReservedItemsDict.ContainsKey(itemName); } public static bool TryGetReservedItemInfo(string itemName, out ReservedItemInfo info) { info = null; if (IsReservedItem(itemName)) { info = syncReservedItemsDict[itemName]; return true; } return false; } public static bool TryGetReservedItemInfo(GrabbableObject item, out ReservedItemInfo info) { info = null; return (Object)(object)item != (Object)null && TryGetReservedItemInfo(item.itemProperties.itemName, out info); } [HarmonyPatch(typeof(StartOfRound), "Awake")] [HarmonyPrefix] public static void ResetValues() { isSynced = false; localPlayerController = null; } [HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")] [HarmonyPostfix] public static void Init(PlayerControllerB __instance) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Expected O, but got Unknown //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Expected O, but got Unknown //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Expected O, but got Unknown localPlayerController = __instance; NetworkManager.Singleton.CustomMessagingManager.RegisterNamedMessageHandler("ReservedItemSlots-OnSwapHotbarClientRpc", new HandleNamedMessageDelegate(OnSwapHotbarClientRpc)); NetworkManager.Singleton.CustomMessagingManager.RegisterNamedMessageHandler("ReservedItemSlots-RequestSyncClientRpc", new HandleNamedMessageDelegate(RequestSyncClientRpc)); if (NetworkManager.Singleton.IsServer) { isSynced = true; syncReservedItemsDict = ReservedItemInfo.reservedItemsDict; syncReservedItemsList = ReservedItemInfo.reservedItemsList; syncReservedItemSlotReps = ReservedItemInfo.reservedItemSlotReps; NetworkManager.Singleton.CustomMessagingManager.RegisterNamedMessageHandler("ReservedItemSlots-OnSwapHotbarServerRpc", new HandleNamedMessageDelegate(OnSwapHotbarServerRpc)); NetworkManager.Singleton.CustomMessagingManager.RegisterNamedMessageHandler("ReservedItemSlots-RequestSyncServerRpc", new HandleNamedMessageDelegate(RequestSyncServerRpc)); { foreach (ReservedItemInfo syncReservedItems in syncReservedItemsList) { ReservedItemInfo reservedItemInfo = ReservedItemInfo.reservedItemsDictDefault[syncReservedItems.itemName]; syncReservedItems.hotbarSlotPriority = reservedItemInfo.hotbarSlotPriority; syncReservedItems.reservedItemIndex = reservedItemInfo.reservedItemIndex; } return; } } isSynced = false; if (canUseModDisabledOnHost) { syncReservedItemsDict = ReservedItemInfo.reservedItemsDict; syncReservedItemsList = ReservedItemInfo.reservedItemsList; syncReservedItemSlotReps = ReservedItemInfo.reservedItemSlotReps; } else { syncReservedItemsDict = new Dictionary<string, ReservedItemInfo>(); syncReservedItemsList = new List<ReservedItemInfo>(); syncReservedItemSlotReps = new List<ReservedItemInfo>(); } RequestSyncWithServer(); } private static void RequestSyncWithServer() { //IL_0033: Unknown result type (might be due to invalid IL or missing references) if (NetworkManager.Singleton.IsClient) { Plugin.Log("Requesting sync with server."); NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("ReservedItemSlots-RequestSyncServerRpc", 0uL, new FastBufferWriter(0, (Allocator)2, -1), (NetworkDelivery)3); } } private static void RequestSyncServerRpc(ulong clientId, FastBufferReader reader) { //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_0178: 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_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Unknown result type (might be due to invalid IL or missing references) if (!NetworkManager.Singleton.IsServer) { return; } Plugin.Log("Receiving sync request from client: " + clientId); int num = 4 * syncReservedItemsList.Count; foreach (ReservedItemInfo syncReservedItems in syncReservedItemsList) { num += 4 + 2 * syncReservedItems.itemName.Length; } FastBufferWriter val = default(FastBufferWriter); ((FastBufferWriter)(ref val))..ctor(num, (Allocator)2, -1); int count = syncReservedItemsList.Count; ((FastBufferWriter)(ref val)).WriteValue<int>(ref count, default(ForPrimitives)); foreach (ReservedItemInfo syncReservedItems2 in syncReservedItemsList) { count = syncReservedItems2.itemName.Length; ((FastBufferWriter)(ref val)).WriteValue<int>(ref count, default(ForPrimitives)); string itemName = syncReservedItems2.itemName; for (int i = 0; i < itemName.Length; i++) { char c = itemName[i]; ((FastBufferWriter)(ref val)).WriteValue<char>(ref c, default(ForPrimitives)); } ((FastBufferWriter)(ref val)).WriteValue<int>(ref syncReservedItems2.hotbarSlotPriority, default(ForPrimitives)); } Plugin.Log("Sent sync to client."); NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("ReservedItemSlots-RequestSyncClientRpc", clientId, val, (NetworkDelivery)3); } private static void RequestSyncClientRpc(ulong clientId, FastBufferReader reader) { //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) if (!NetworkManager.Singleton.IsClient || NetworkManager.Singleton.IsServer) { return; } PlayerPatcher.isSynced = false; isSynced = true; syncReservedItemsDict = new Dictionary<string, ReservedItemInfo>(); syncReservedItemsList = new List<ReservedItemInfo>(); syncReservedItemSlotReps = new List<ReservedItemInfo>(); Plugin.Log("Receiving sync from server."); int num = default(int); ((FastBufferReader)(ref reader)).ReadValue<int>(ref num, default(ForPrimitives)); int num2 = default(int); char c = default(char); for (int i = 0; i < num; i++) { ((FastBufferReader)(ref reader)).ReadValue<int>(ref num2, default(ForPrimitives)); ((FastBufferReader)(ref reader)).TryBeginRead(2 * num2); string text = ""; for (int j = 0; j < num2; j++) { ((FastBufferReader)(ref reader)).ReadValue<char>(ref c, default(ForPrimitives)); text += c; } bool flag = ReservedItemInfo.reservedItemsDict.ContainsKey(text); ReservedItemInfo reservedItemInfo = (ReservedItemInfo.reservedItemsDict.ContainsKey(text) ? ReservedItemInfo.reservedItemsDict[text] : new ReservedItemInfo { itemName = text }); ((FastBufferReader)(ref reader)).ReadValue<int>(ref reservedItemInfo.hotbarSlotPriority, default(ForPrimitives)); Plugin.Log("Receiving sync for item: - Item: " + reservedItemInfo.itemName + " Prio: " + reservedItemInfo.hotbarSlotPriority); ReservedItemInfo.AddItemInfoToList(reservedItemInfo, syncReservedItemsList, syncReservedItemsDict, syncReservedItemSlotReps); } Plugin.Log("Received sync for " + syncReservedItemSlotReps.Count + " reserved item slots. (" + syncReservedItemsList.Count + " items total)"); } private static void SendSwapHotbarUpdate(int hotbarSlot) { //IL_003b: 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_0059: Unknown result type (might be due to invalid IL or missing references) if (NetworkManager.Singleton.IsClient) { Plugin.Log("Sending OnSwapReservedHotbar update to server. Hotbar slot: " + hotbarSlot); FastBufferWriter val = default(FastBufferWriter); ((FastBufferWriter)(ref val))..ctor(4, (Allocator)2, -1); ((FastBufferWriter)(ref val)).WriteValue<int>(ref hotbarSlot, default(ForPrimitives)); NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("ReservedItemSlots-OnSwapHotbarServerRpc", 0uL, val, (NetworkDelivery)3); } } private static void OnSwapHotbarServerRpc(ulong clientId, FastBufferReader reader) { //IL_001a: 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_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_006e: 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_008a: Unknown result type (might be due to invalid IL or missing references) if (NetworkManager.Singleton.IsServer) { int num = default(int); ((FastBufferReader)(ref reader)).ReadValue<int>(ref num, default(ForPrimitives)); Plugin.Log("Receiving OnSwapReservedHotbar update from client. ClientId: " + clientId + " Slot: " + num); FastBufferWriter val = default(FastBufferWriter); ((FastBufferWriter)(ref val))..ctor(12, (Allocator)2, -1); ((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref num, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref clientId, default(ForPrimitives)); NetworkManager.Singleton.CustomMessagingManager.SendNamedMessageToAll("ReservedItemSlots-OnSwapHotbarClientRpc", val, (NetworkDelivery)3); } } private static void OnSwapHotbarClientRpc(ulong clientId, FastBufferReader reader) { //IL_001a: 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_002d: 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) if (NetworkManager.Singleton.IsClient) { int hotbarSlot = default(int); ((FastBufferReader)(ref reader)).ReadValue<int>(ref hotbarSlot, default(ForPrimitives)); ulong num = default(ulong); ((FastBufferReader)(ref reader)).ReadValue<ulong>(ref num, default(ForPrimitives)); Plugin.Log("Receiving OnSwapReservedHotbar update from client. ClientId: " + num + " Slot: " + hotbarSlot); if (num != localPlayerController.actualClientId && !TryUpdateClientHotbarSlot(num, hotbarSlot)) { Plugin.Log("Failed to receive hotbar swap index from Client: " + num); } } } private static bool TryUpdateClientHotbarSlot(ulong clientId, int hotbarSlot) { for (int i = 0; i < StartOfRound.Instance.allPlayerScripts.Length; i++) { PlayerControllerB val = StartOfRound.Instance.allPlayerScripts[i]; if (val.actualClientId == clientId) { CallSwitchToItemSlotMethod(val, hotbarSlot); return true; } } return false; } public static void SwapHotbarSlot(int hotbarIndex) { SendSwapHotbarUpdate(hotbarIndex); CallSwitchToItemSlotMethod(localPlayerController, hotbarIndex); } private static void CallSwitchToItemSlotMethod(PlayerControllerB playerController, int hotbarIndex) { if (!((Object)(object)playerController == (Object)null) && playerController.ItemSlots != null && hotbarIndex >= 0 && hotbarIndex < playerController.ItemSlots.Length) { if ((Object)(object)playerController == (Object)(object)localPlayerController) { ShipBuildModeManager.Instance.CancelBuildMode(true); playerController.playerBodyAnimator.SetBool("GrabValidated", false); } ReservedItemPatcher.SwitchToItemSlot(playerController, hotbarIndex); if ((Object)(object)playerController.currentlyHeldObjectServer != (Object)null) { ((Component)playerController.currentlyHeldObjectServer).gameObject.GetComponent<AudioSource>().PlayOneShot(playerController.currentlyHeldObjectServer.itemProperties.grabSFX, 0.6f); } } } } } namespace ReservedItemSlotCore.Input { internal class InputUtilsCompat { internal static bool Enabled => Plugin.IsModLoaded("com.rune580.LethalCompanyInputUtils"); internal static InputActionAsset Asset => ((LcInputActions)IngameKeybinds.Instance).Asset; public static InputAction FocusReservedHotbarHotkey => IngameKeybinds.Instance.FocusReservedHotbarHotkey; internal static void Init() { if (Enabled && IngameKeybinds.Instance == null) { IngameKeybinds.Instance = new IngameKeybinds(); } } } internal class IngameKeybinds : LcInputActions { internal static IngameKeybinds Instance; [InputAction("<Keyboard>/leftAlt", GamepadPath = "<Gamepad>/leftShoulder", Name = "Swap hotbars")] internal InputAction FocusReservedHotbarHotkey { get; set; } internal static InputActionAsset GetAsset() { return ((LcInputActions)Instance).Asset; } } [HarmonyPatch] internal class Keybinds { public static InputActionAsset Asset; public static InputActionMap ActionMap; public static InputAction FocusReservedHotbarAction; public static InputAction RawScrollAction; public static bool holdingModifierKey; public static bool scrollingReservedHotbar; public static PlayerControllerB localPlayerController => StartOfRound.Instance?.localPlayerController; [HarmonyPatch(typeof(PreInitSceneScript), "Awake")] [HarmonyPrefix] public static void AddToKeybindMenu() { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Expected O, but got Unknown //IL_007c: 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_009b: Expected O, but got Unknown if (InputUtilsCompat.Enabled) { Asset = InputUtilsCompat.Asset; FocusReservedHotbarAction = InputUtilsCompat.FocusReservedHotbarHotkey; } else { Asset = ScriptableObject.CreateInstance<InputActionAsset>(); ActionMap = new InputActionMap("ReservedItemSlots"); InputActionSetupExtensions.AddActionMap(Asset, ActionMap); FocusReservedHotbarAction = InputActionSetupExtensions.AddAction(ActionMap, "ReservedItemSlots.FocusReservedHotbar", (InputActionType)0, ConfigSettings.focusReservedHotbarHotkey.Value, (string)null, (string)null, (string)null, (string)null); InputActionSetupExtensions.AddBinding(FocusReservedHotbarAction, "<Gamepad>/leftShoulder", (string)null, (string)null, (string)null); } RawScrollAction = new InputAction("ReservedItemSlots.RawScroll", (InputActionType)0, "<Mouse>/scroll/y", (string)null, (string)null, (string)null); } [HarmonyPatch(typeof(StartOfRound), "OnEnable")] [HarmonyPrefix] public static void OnEnable() { Asset.Enable(); RawScrollAction.Enable(); FocusReservedHotbarAction.performed += FocusReservedHotbarSlotsAction; if (!ConfigSettings.toggleFocusReservedHotbar.Value) { FocusReservedHotbarAction.canceled += UnfocusReservedHotbarSlotsPerformed; } RawScrollAction.performed += OnScrollReservedHotbar; } [HarmonyPatch(typeof(StartOfRound), "OnDisable")] [HarmonyPrefix] public static void OnDisable() { Asset.Disable(); RawScrollAction.Disable(); FocusReservedHotbarAction.performed -= FocusReservedHotbarSlotsAction; if (!ConfigSettings.toggleFocusReservedHotbar.Value) { FocusReservedHotbarAction.canceled -= UnfocusReservedHotbarSlotsPerformed; } RawScrollAction.performed -= OnScrollReservedHotbar; } private static void FocusReservedHotbarSlotsAction(CallbackContext context) { if ((Object)(object)localPlayerController == (Object)null || !((NetworkBehaviour)localPlayerController).IsOwner || !localPlayerController.isPlayerControlled || (((NetworkBehaviour)localPlayerController).IsServer && !localPlayerController.isHostPlayerObject) || SyncManager.numReservedItemSlots <= 0 || !HUDPatcher.hasReservedItemSlotsAndEnabled) { return; } if (!ConfigSettings.toggleFocusReservedHotbar.Value) { holdingModifierKey = true; } if (((CallbackContext)(ref context)).performed && ReservedItemPatcher.CanSwapToReservedHotbarSlot()) { if (!ConfigSettings.toggleFocusReservedHotbar.Value) { ReservedItemPatcher.FocusReservedHotbarSlots(active: true); } else { ReservedItemPatcher.FocusReservedHotbarSlots(!PlayerPatcher.playerDataLocal.currentItemSlotIsReserved); } } } private static void UnfocusReservedHotbarSlotsPerformed(CallbackContext context) { if (!((Object)(object)localPlayerController == (Object)null) && ((NetworkBehaviour)localPlayerController).IsOwner && (!((NetworkBehaviour)localPlayerController).IsServer || localPlayerController.isHostPlayerObject)) { holdingModifierKey = false; if (((CallbackContext)(ref context)).canceled && ReservedItemPatcher.CanSwapToReservedHotbarSlot()) { ReservedItemPatcher.FocusReservedHotbarSlots(active: false); } } } private static void OnScrollReservedHotbar(CallbackContext context) { //IL_00ac: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)localPlayerController == (Object)null) && ((NetworkBehaviour)localPlayerController).IsOwner && (!((NetworkBehaviour)localPlayerController).IsServer || localPlayerController.isHostPlayerObject) && ((CallbackContext)(ref context)).performed && !PlayerPatcher.playerDataLocal.throwingObject && !scrollingReservedHotbar && PlayerPatcher.playerDataLocal.currentItemSlotIsReserved && PlayerPatcher.playerDataLocal.grabbingReservedItemInfo == null) { scrollingReservedHotbar = true; MethodInfo method = ((object)localPlayerController).GetType().GetMethod("ScrollMouse_performed", BindingFlags.Instance | BindingFlags.NonPublic); method.Invoke(localPlayerController, new object[1] { context }); ((MonoBehaviour)localPlayerController).StartCoroutine(ResetScrollDelayed()); } static IEnumerator ResetScrollDelayed() { yield return null; yield return (object)new WaitForEndOfFrame(); scrollingReservedHotbar = false; } } } } namespace ReservedItemSlotCore.Patches { [HarmonyPatch] public static class HUDPatcher { private static bool usingController; private static float iconWidth; private static float xPos; private static TextMeshProUGUI hotkeyTooltip; public static List<Image> reservedItemSlots; public static PlayerControllerB localPlayerController => StartOfRound.Instance?.localPlayerController; public static bool localPlayerUsingController => (Object)(object)StartOfRound.Instance != (Object)null && StartOfRound.Instance.localPlayerUsingController; public static bool hasReservedItemSlotsAndEnabled => reservedItemSlots != null && reservedItemSlots.Count > 0 && ((Component)reservedItemSlots[0]).gameObject.activeSelf && ((Behaviour)reservedItemSlots[0]).enabled; [HarmonyPatch(typeof(HUDManager), "Awake")] [HarmonyPostfix] public static void Initialize(HUDManager __instance) { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) CanvasScaler componentInParent = ((Component)__instance.itemSlotIconFrames[0]).GetComponentInParent<CanvasScaler>(); AspectRatioFitter componentInParent2 = ((Component)__instance.itemSlotIconFrames[0]).GetComponentInParent<AspectRatioFitter>(); iconWidth = ((Component)__instance.itemSlotIconFrames[0]).GetComponent<RectTransform>().sizeDelta.x; xPos = componentInParent.referenceResolution.x / 2f / componentInParent2.aspectRatio - iconWidth / 4f; reservedItemSlots = new List<Image>(); } [HarmonyPatch(typeof(StartOfRound), "Update")] [HarmonyPostfix] public static void UpdateUsingController(StartOfRound __instance) { if (!((Object)(object)__instance.localPlayerController == (Object)null) && !((Object)(object)hotkeyTooltip == (Object)null) && ((Component)hotkeyTooltip).gameObject.activeSelf && ((Behaviour)hotkeyTooltip).enabled && __instance.localPlayerUsingController != usingController) { usingController = __instance.localPlayerUsingController; UpdateHotkeyTooltipText(); } } public static void AddNewHotbarSlotsHud() { //IL_0048: 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_0069: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0305: Unknown result type (might be due to invalid IL or missing references) //IL_031e: Unknown result type (might be due to invalid IL or missing references) //IL_0333: Unknown result type (might be due to invalid IL or missing references) //IL_0340: Unknown result type (might be due to invalid IL or missing references) //IL_034a: Unknown result type (might be due to invalid IL or missing references) //IL_035e: Unknown result type (might be due to invalid IL or missing references) //IL_037a: Unknown result type (might be due to invalid IL or missing references) //IL_02cb: Unknown result type (might be due to invalid IL or missing references) //IL_0195: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_0203: Unknown result type (might be due to invalid IL or missing references) if (PlayerPatcher.reservedHotbarSize <= 0) { return; } List<Image> list = new List<Image>(HUDManager.Instance.itemSlotIconFrames); List<Image> list2 = new List<Image>(HUDManager.Instance.itemSlotIcons); float y = ((Component)HUDManager.Instance.itemSlotIconFrames[0]).GetComponent<RectTransform>().sizeDelta.y; Vector3 eulerAngles = ((Transform)((Component)HUDManager.Instance.itemSlotIconFrames[0]).GetComponent<RectTransform>()).eulerAngles; Vector3 eulerAngles2 = ((Transform)((Component)HUDManager.Instance.itemSlotIcons[0]).GetComponent<RectTransform>()).eulerAngles; Plugin.Log($"Adding {SyncManager.syncReservedItemSlotReps.Count} reserved item slots to the inventory HUD. Previous inventory HUD size: {PlayerPatcher.playerDataLocal.reservedHotbarStartIndex}"); int num = 0; int num2 = 0; for (int i = 0; i < SyncManager.syncReservedItemSlotReps.Count; i++) { ReservedItemInfo reservedItemInfo = SyncManager.syncReservedItemSlotReps[i]; Plugin.Log($"Adding Reserved item slot for item types [{reservedItemInfo.itemName}]. Inventory index: {list.Count}"); float num3 = ((Graphic)HUDManager.Instance.itemSlotIconFrames[0]).rectTransform.anchoredPosition.y + 1.125f * y * (float)((reservedItemInfo.hotbarSlotPriority >= 0) ? num : num2); Image val = Object.Instantiate<Image>(HUDManager.Instance.itemSlotIconFrames[0], ((Component)HUDManager.Instance.itemSlotIconFrames[0]).transform.parent); ((Object)val).name = "Slot" + list.Count + " [ReservedItemSlot]"; ((Graphic)val).rectTransform.anchoredPosition = new Vector2((reservedItemInfo.hotbarSlotPriority >= 0) ? xPos : (0f - xPos), num3); ((Transform)((Graphic)val).rectTransform).eulerAngles = eulerAngles; CanvasGroup val2 = ((Component)val).gameObject.AddComponent<CanvasGroup>(); val2.ignoreParentGroups = ConfigSettings.preventReservedItemSlotFade.Value; val2.alpha = 1f; Image component = ((Component)((Component)val).transform.GetChild(0)).GetComponent<Image>(); ((Object)component).name = "Icon"; ((Transform)((Graphic)component).rectTransform).eulerAngles = eulerAngles2; reservedItemSlots.Add(val); list.Insert(PlayerPatcher.playerDataLocal.reservedHotbarStartIndex + i, val); list2.Insert(PlayerPatcher.playerDataLocal.reservedHotbarStartIndex + i, component); if (reservedItemInfo.hotbarSlotPriority >= 0) { num++; } else { num2++; } } if (SyncManager.numReservedItemSlots > 0) { if ((Object)(object)hotkeyTooltip == (Object)null) { hotkeyTooltip = new GameObject("ReservedItemSlotTooltip", new Type[2] { typeof(RectTransform), typeof(TextMeshProUGUI) }).GetComponent<TextMeshProUGUI>(); } RectTransform rectTransform = ((TMP_Text)hotkeyTooltip).rectTransform; ((Component)rectTransform).transform.parent = ((Component)reservedItemSlots[0]).transform; ((Transform)rectTransform).localScale = Vector3.one; rectTransform.sizeDelta = new Vector2(((Graphic)list[0]).rectTransform.sizeDelta.x * 2f, 10f); rectTransform.pivot = Vector2.one / 2f; rectTransform.anchoredPosition3D = new Vector3(0f, (0f - rectTransform.sizeDelta.x / 2f) * 1.2f, 0f); ((TMP_Text)hotkeyTooltip).font = ((TMP_Text)HUDManager.Instance.controlTipLines[0]).font; ((TMP_Text)hotkeyTooltip).fontSize = 7f; ((TMP_Text)hotkeyTooltip).alignment = (TextAlignmentOptions)514; UpdateHotkeyTooltipText(); } HUDManager.Instance.itemSlotIconFrames = list.ToArray(); HUDManager.Instance.itemSlotIcons = list2.ToArray(); Plugin.Log($"Finished adding {PlayerPatcher.reservedHotbarSize} Reserved Item slots in the inventory HUD."); } public static void UpdateHotkeyTooltipText() { //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) //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)(object)localPlayerController == (Object)null) && !((Object)(object)hotkeyTooltip == (Object)null) && Keybinds.FocusReservedHotbarAction != null && !Plugin.IsModLoaded("com.potatoepet.AdvancedCompany")) { int num = (localPlayerUsingController ? 1 : 0); InputBinding val = Keybinds.FocusReservedHotbarAction.bindings[num]; string displayName = ConfigSettings.GetDisplayName(((InputBinding)(ref val)).path); ((TMP_Text)hotkeyTooltip).text = (ConfigSettings.toggleFocusReservedHotbar.Value ? $"Toggle: [{displayName}]" : $"Hold: [{displayName}]"); } } public static void UpdateHUD() { //IL_0047: 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) if (AdvancedCompanyPatcher.Enabled) { return; } int num = 0; int num2 = 0; for (int i = 0; i < PlayerPatcher.reservedHotbarSize; i++) { ReservedItemInfo reservedItemInfo = SyncManager.syncReservedItemSlotReps[i]; int num3 = PlayerPatcher.playerDataLocal.reservedHotbarStartIndex + i; float num4 = ((Graphic)HUDManager.Instance.itemSlotIconFrames[0]).rectTransform.anchoredPosition.y + 1.125f * iconWidth * (float)((reservedItemInfo.hotbarSlotPriority >= 0) ? num : num2); ((Graphic)HUDManager.Instance.itemSlotIconFrames[num3]).rectTransform.anchoredPosition = new Vector2((reservedItemInfo.hotbarSlotPriority >= 0) ? xPos : (0f - xPos), num4); if (reservedItemInfo.hotbarSlotPriority >= 0) { num++; } else { num2++; } } } } [HarmonyPatch] public static class MouseScrollPatcher { public static PlayerControllerB localPlayerController => StartOfRound.Instance?.localPlayerController; [HarmonyPatch(typeof(PlayerControllerB), "NextItemSlot")] [HarmonyPrefix] public static void CorrectReservedScrollDirectionNextItemSlot(ref bool forward) { if (Keybinds.scrollingReservedHotbar) { forward = Keybinds.RawScrollAction.ReadValue<float>() > 0f; } } [HarmonyPatch(typeof(PlayerControllerB), "SwitchItemSlotsServerRpc")] [HarmonyPrefix] public static void CorrectReservedScrollDirectionServerRpc(ref bool forward) { if (Keybinds.scrollingReservedHotbar) { forward = Keybinds.RawScrollAction.ReadValue<float>() > 0f; } } [HarmonyPatch(typeof(PlayerControllerB), "ScrollMouse_performed")] [HarmonyPrefix] public static bool PreventInvertedScrollingReservedHotbar(CallbackContext context) { //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) if (StartOfRound.Instance.localPlayerUsingController || SyncManager.numReservedItemSlots <= 0) { return true; } if (PlayerPatcher.playerDataLocal.currentItemSlotIsReserved) { if (!HUDPatcher.hasReservedItemSlotsAndEnabled) { return true; } if (HUDPatcher.reservedItemSlots.Count >= 2 && ((Graphic)HUDPatcher.reservedItemSlots[1]).rectTransform.anchoredPosition.y - ((Graphic)HUDPatcher.reservedItemSlots[0]).rectTransform.anchoredPosition.y <= 5f) { return true; } if (!Keybinds.scrollingReservedHotbar || SyncManager.numReservedItemSlots == 1 || (PlayerPatcher.playerDataLocal.GetNumHeldReservedItems() == 1 && (Object)(object)localPlayerController.ItemSlots[localPlayerController.currentItemSlot] != (Object)null)) { return false; } } return true; } } [HarmonyPatch] public static class ReservedItemPatcher { public static int indexInHotbar; public static int indexInReservedHotbar; public static PlayerControllerB localPlayerController => PlayerPatcher.localPlayerController; public static int reservedHotbarSize => SyncManager.numReservedItemSlots; private static GrabbableObject GetCurrentlyGrabbingObject(PlayerControllerB playerController) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown return (GrabbableObject)Traverse.Create((object)playerController).Field("currentlyGrabbingObject").GetValue(); } private static void SetCurrentlyGrabbingObject(PlayerControllerB playerController, GrabbableObject grabbable) { Traverse.Create((object)playerController).Field("currentlyGrabbingObject").SetValue((object)grabbable); } [HarmonyPatch(typeof(PlayerControllerB), "BeginGrabObject")] [HarmonyPrefix] public static bool GrabReservedItemPrefix(PlayerControllerB __instance) { //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) if ((!SyncManager.isSynced && !SyncManager.canUseModDisabledOnHost) || !HUDPatcher.hasReservedItemSlotsAndEnabled) { return true; } PlayerPatcher.playerDataLocal.grabbingReservedItemInfo = null; PlayerPatcher.playerDataLocal.grabbingReservedItem = null; PlayerPatcher.playerDataLocal.previousHotbarIndex = -1; if (PlayerPatcher.playerDataLocal.currentItemSlotIsReserved && !ConfigSettings.toggleFocusReservedHotbar.Value) { return false; } if (__instance.twoHanded || __instance.sinkingValue > 0.73f) { return true; } Ray val = default(Ray); ((Ray)(ref val))..ctor(((Component)__instance.gameplayCamera).transform.position, ((Component)__instance.gameplayCamera).transform.forward); RaycastHit val2 = default(RaycastHit); if (Physics.Raycast(val, ref val2, __instance.grabDistance, PlayerPatcher.INTERACTABLE_OBJECT_MASK) && ((Component)((RaycastHit)(ref val2)).collider).gameObject.layer != 8 && ((Component)((RaycastHit)(ref val2)).collider).tag == "PhysicsProp") { GrabbableObject component = ((Component)((Component)((RaycastHit)(ref val2)).collider).transform).gameObject.GetComponent<GrabbableObject>(); if ((Object)(object)component != (Object)null && !__instance.inSpecialInteractAnimation && !component.isHeld && !component.isPocketed) { NetworkObject networkObject = ((NetworkBehaviour)component).NetworkObject; if ((Object)(object)networkObject != (Object)null && networkObject.IsSpawned && SyncManager.TryGetReservedItemInfo(component, out var info)) { Plugin.Log("Beginning grab on reserved item: " + info.itemName); PlayerPatcher.playerDataLocal.grabbingReservedItemInfo = info; PlayerPatcher.playerDataLocal.grabbingReservedItem = component; PlayerPatcher.playerDataLocal.previousHotbarIndex = __instance.currentItemSlot; } } } return true; } [HarmonyPatch(typeof(PlayerControllerB), "BeginGrabObject")] [HarmonyPostfix] public static void GrabReservedItemPostfix(PlayerControllerB __instance) { if (PlayerPatcher.playerDataLocal.grabbingReservedItemInfo != null) { SetSpecialGrabAnimationBool(__instance, setTrue: false); } } [HarmonyPatch(typeof(PlayerControllerB), "GrabObjectClientRpc")] [HarmonyPrefix] public static void GrabReservedItemClientRpcPrefix(bool grabValidated, NetworkObjectReference grabbedObject, PlayerControllerB __instance) { if ((!SyncManager.isSynced && !SyncManager.canUseModDisabledOnHost) || !NetworkHelper.IsClientExecStage((NetworkBehaviour)(object)__instance)) { return; } ReservedPlayerData reservedPlayerData = PlayerPatcher.allPlayerData[__instance]; NetworkObject val = default(NetworkObject); if ((Object)(object)NetworkManager.Singleton != (Object)null && NetworkManager.Singleton.IsListening && grabValidated && ((NetworkObjectReference)(ref grabbedObject)).TryGet(ref val, (NetworkManager)null)) { GrabbableObject component = ((Component)val).GetComponent<GrabbableObject>(); if (SyncManager.TryGetReservedItemInfo(component, out var info)) { if (IsItemSlotEmpty(info, __instance)) { Plugin.Log("OnGrabReservedItem for Player: " + ((Object)__instance).name + " Item: " + info.itemName); reservedPlayerData.grabbingReservedItemInfo = info; reservedPlayerData.grabbingReservedItem = component; reservedPlayerData.previousHotbarIndex = __instance.currentItemSlot; return; } Plugin.LogWarning("OnGrabReservedItem SlotFilled. Player: " + ((Object)__instance).name + " Item: " + info.itemName + " Slot: " + (reservedPlayerData.reservedHotbarStartIndex + info.reservedItemIndex)); } } reservedPlayerData.grabbingReservedItemInfo = null; reservedPlayerData.grabbingReservedItem = null; reservedPlayerData.previousHotbarIndex = -1; } [HarmonyPatch(typeof(PlayerControllerB), "GrabObjectClientRpc")] [HarmonyPostfix] public static void GrabReservedItemClientRpcPostfix(bool grabValidated, NetworkObjectReference grabbedObject, PlayerControllerB __instance) { //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Unknown result type (might be due to invalid IL or missing references) //IL_019c: Unknown result type (might be due to invalid IL or missing references) if ((!SyncManager.isSynced && SyncManager.canUseModDisabledOnHost) || !NetworkHelper.IsClientExecStage((NetworkBehaviour)(object)__instance)) { return; } ReservedPlayerData reservedPlayerData = PlayerPatcher.allPlayerData[__instance]; if (reservedPlayerData.grabbingReservedItemInfo == null) { return; } if ((Object)(object)NetworkManager.Singleton != (Object)null && NetworkManager.Singleton.IsListening) { NetworkObject val = default(NetworkObject); if (grabValidated && ((NetworkObjectReference)(ref grabbedObject)).TryGet(ref val, (NetworkManager)null)) { GrabbableObject component = ((Component)val).GetComponent<GrabbableObject>(); if (SyncManager.TryGetReservedItemInfo(component, out var info)) { SetSpecialGrabAnimationBool(__instance, (Object)(object)reservedPlayerData.previouslyHeldItem != (Object)null, reservedPlayerData.previouslyHeldItem); Animator playerBodyAnimator = __instance.playerBodyAnimator; AnimatorStateInfo currentAnimatorStateInfo = __instance.playerBodyAnimator.GetCurrentAnimatorStateInfo(2); playerBodyAnimator.Play(((AnimatorStateInfo)(ref currentAnimatorStateInfo)).shortNameHash, 2, 1f); if ((Object)(object)reservedPlayerData.previouslyHeldItem != (Object)null) { reservedPlayerData.previouslyHeldItem.EnableItemMeshes(true); } ForceDisableItemMesh(reservedPlayerData.grabbingReservedItem); Traverse.Create((object)component).Field("previousPlayerHeldBy").SetValue((object)__instance); if ((Object)(object)__instance != (Object)(object)localPlayerController) { Plugin.Log("OnGrabReservedItem completed. Player: " + ((Object)__instance).name + " Item: " + info.itemName + " Switching to previous slot: " + reservedPlayerData.previousHotbarIndex); SwitchToItemSlot(__instance, reservedPlayerData.previousHotbarIndex); Animator playerBodyAnimator2 = __instance.playerBodyAnimator; currentAnimatorStateInfo = __instance.playerBodyAnimator.GetCurrentAnimatorStateInfo(2); playerBodyAnimator2.Play(((AnimatorStateInfo)(ref currentAnimatorStateInfo)).shortNameHash, 2, 1f); reservedPlayerData.grabbingReservedItemInfo = null; reservedPlayerData.grabbingReservedItem = null; reservedPlayerData.previousHotbarIndex = -1; } else { int num = reservedPlayerData.reservedHotbarStartIndex + reservedPlayerData.grabbingReservedItemInfo.reservedItemIndex; ((Component)HUDManager.Instance.itemSlotIconFrames[num]).GetComponent<Animator>().SetBool("selectedSlot", false); ((Component)HUDManager.Instance.itemSlotIconFrames[reservedPlayerData.previousHotbarIndex]).GetComponent<Animator>().SetBool("selectedSlot", true); ((Component)HUDManager.Instance.itemSlotIconFrames[num]).GetComponent<Animator>().Play("PanelLines", 0, 1f); ((Component)HUDManager.Instance.itemSlotIconFrames[reservedPlayerData.previousHotbarIndex]).GetComponent<Animator>().Play("PanelEnlarge", 0, 1f); } return; } } else if ((Object)(object)__instance == (Object)(object)localPlayerController) { Plugin.Log("Failed to validate ReservedItemGrab by the local player. Object id: " + ((NetworkObjectReference)(ref grabbedObject)).NetworkObjectId + "."); Traverse.Create((object)localPlayerController).Field("grabInvalidated").SetValue((object)true); } else { Plugin.Log("Failed to validate ReservedItemGrab by player with id: " + ((Object)__instance).name + ". Object id: " + ((NetworkObjectReference)(ref grabbedObject)).NetworkObjectId + "."); } } reservedPlayerData.grabbingReservedItemInfo = null; reservedPlayerData.grabbingReservedItem = null; reservedPlayerData.previousHotbarIndex = -1; } [HarmonyPatch(typeof(GrabbableObject), "GrabItemOnClient")] [HarmonyPrefix] public static void OnReservedItemGrabbed(GrabbableObject __instance) { if (PlayerPatcher.playerDataLocal.grabbingReservedItemInfo != null && !((Object)(object)__instance != (Object)(object)GetCurrentlyGrabbingObject(localPlayerController))) { ((MonoBehaviour)localPlayerController).StartCoroutine(OnReservedItemGrabbedEndOfFrame()); } IEnumerator OnReservedItemGrabbedEndOfFrame() { yield return (object)new WaitForEndOfFrame(); SwitchToItemSlot(localPlayerController, PlayerPatcher.playerDataLocal.previousHotbarIndex); PlayerPatcher.playerDataLocal.grabbingReservedItemInfo = null; PlayerPatcher.playerDataLocal.grabbingReservedItem = null; PlayerPatcher.playerDataLocal.previousHotbarIndex = -1; __instance.EnableItemMeshes(false); __instance.PocketItem(); Animator playerBodyAnimator = localPlayerController.playerBodyAnimator; AnimatorStateInfo currentAnimatorStateInfo = localPlayerController.playerBodyAnimator.GetCurrentAnimatorStateInfo(2); playerBodyAnimator.Play(((AnimatorStateInfo)(ref currentAnimatorStateInfo)).shortNameHash, 2, 1f); } } [HarmonyPatch(typeof(HUDManager), "ClearControlTips")] [HarmonyPrefix] public static bool PreventClearControlTipsGrabbingReservedItem(HUDManager __instance) { return PlayerPatcher.playerDataLocal == null || (Object)(object)PlayerPatcher.playerDataLocal.grabbingReservedItem == (Object)null; } [HarmonyPatch(typeof(GrabbableObject), "SetControlTipsForItem")] [HarmonyPrefix] public static bool PreventUpdateControlTipsGrabbingReservedItem(GrabbableObject __instance) { return PlayerPatcher.playerDataLocal == null || (Object)(object)PlayerPatcher.playerDataLocal.grabbingReservedItem != (Object)(object)__instance; } [HarmonyPatch(typeof(PlayerControllerB), "SetSpecialGrabAnimationBool")] [HarmonyPrefix] public static bool PreventSpecialGrabAnimationReservedItem(bool setTrue, PlayerControllerB __instance, GrabbableObject currentItem = null) { return true; } [HarmonyPatch(typeof(PlayerControllerB), "SwitchToItemSlot")] [HarmonyPrefix] public static void DebugSwitchToItemSlot(int slot, PlayerControllerB __instance) { if (!HUDPatcher.hasReservedItemSlotsAndEnabled) { return; } ReservedPlayerData reservedPlayerData = PlayerPatcher.allPlayerData[__instance]; if (reservedPlayerData == null) { Plugin.LogError("PlayerData null for player: " + ((Object)__instance).name); } else { if (!reservedPlayerData.IsReservedItemSlot(slot)) { return; } string text = ""; reservedPlayerData = PlayerPatcher.allPlayerData[__instance]; if (slot < 0) { text = "Called SwitchToItemSlot on slot: " + slot; } else if (slot >= __instance.ItemSlots.Length) { text = "Called SwitchToItemSlot on slot: " + slot + " HotbarSize: " + __instance.ItemSlots.Length; } else { if (slot < HUDManager.Instance.itemSlotIconFrames.Length) { return; } text = "Called SwitchToItemSlot on slot: " + slot + " NumItemSlotsHUD: " + HUDManager.Instance.itemSlotIconFrames.Length; } text += "\n\n"; text = text + reservedPlayerData.DumpData() + "\n\nReporting this error to Flip would be greatly appreciated!"; Debug.LogError((object)text); } } [HarmonyPatch(typeof(PlayerControllerB), "SwitchToItemSlot")] [HarmonyPostfix] public static void UpdateFocusReservedHotbar(int slot, PlayerControllerB __instance) { if (HUDPatcher.hasReservedItemSlotsAndEnabled && PlayerPatcher.allPlayerData.TryGetValue(__instance, out var value)) { value.inReservedHotbarSlots = value.IsReservedItemSlot(__instance.currentItemSlot); } } [HarmonyPatch(typeof(PlayerControllerB), "FirstEmptyItemSlot")] [HarmonyPostfix] public static void GetReservedItemSlotPlacementIndex(ref int __result, PlayerControllerB __instance) { if (reservedHotbarSize <= 0 || !HUDPatcher.hasReservedItemSlotsAndEnabled) { return; } ReservedPlayerData reservedPlayerData = PlayerPatcher.allPlayerData[__instance]; ReservedItemInfo grabbingReservedItemInfo = reservedPlayerData.grabbingReservedItemInfo; if (grabbingReservedItemInfo != null) { if (IsItemSlotEmpty(grabbingReservedItemInfo, __instance)) { __result = reservedPlayerData.reservedHotbarStartIndex + grabbingReservedItemInfo.reservedItemIndex; return; } reservedPlayerData.grabbingReservedItemInfo = null; reservedPlayerData.grabbingReservedItem = null; reservedPlayerData.previousHotbarIndex = -1; } if (!reservedPlayerData.IsReservedItemSlot(__result)) { return; } __result = -1; for (int i = 0; i < __instance.ItemSlots.Length; i++) { if (!reservedPlayerData.IsReservedItemSlot(i) && (Object)(object)__instance.ItemSlots[i] == (Object)null) { __result = i; break; } } } [HarmonyPatch(typeof(PlayerControllerB), "NextItemSlot")] [HarmonyPostfix] public static void OnNextItemSlot(ref int __result, bool forward, PlayerControllerB __instance) { if (reservedHotbarSize <= 0 || !HUDPatcher.hasReservedItemSlotsAndEnabled) { return; } ReservedPlayerData reservedPlayerData = PlayerPatcher.allPlayerData[__instance]; bool flag = reservedPlayerData.IsReservedItemSlot(__result); if (flag == reservedPlayerData.inReservedHotbarSlots && (!flag || (Object)(object)__instance.ItemSlots[__result] != (Object)null)) { return; } int num = (forward ? 1 : (-1)); __result = __instance.currentItemSlot + num; __result = ((__result < 0) ? (__instance.ItemSlots.Length - 1) : ((__result < __instance.ItemSlots.Length) ? __result : 0)); bool flag2 = reservedPlayerData.IsReservedItemSlot(__result); if (!reservedPlayerData.inReservedHotbarSlots) { if (flag2) { __result = (forward ? ((reservedPlayerData.reservedHotbarStartIndex + reservedHotbarSize) % __instance.ItemSlots.Length) : (reservedPlayerData.reservedHotbarStartIndex - 1)); } return; } __result = (flag2 ? __result : (forward ? reservedPlayerData.reservedHotbarStartIndex : (reservedPlayerData.reservedHotbarStartIndex + reservedHotbarSize - 1))); int numHeldReservedItems = reservedPlayerData.GetNumHeldReservedItems(); while (numHeldReservedItems > 0 && __result != reservedPlayerData.currentItemSlot && (Object)(object)__instance.ItemSlots[__result] == (Object)null) { __result += num; __result = ((!reservedPlayerData.IsReservedItemSlot(__result)) ? (forward ? reservedPlayerData.reservedHotbarStartIndex : (reservedPlayerData.reservedHotbarStartIndex + reservedHotbarSize - 1)) : __result); } } [HarmonyPatch(typeof(PlayerControllerB), "LateUpdate")] [HarmonyPrefix] public static void RefocusReservedHotbarAfterAnimation(PlayerControllerB __instance) { if (HUDPatcher.hasReservedItemSlotsAndEnabled && !((Object)(object)__instance != (Object)(object)localPlayerController) && !ConfigSettings.toggleFocusReservedHotbar.Value && Keybinds.holdingModifierKey != PlayerPatcher.playerDataLocal.currentItemSlotIsReserved && CanSwapToReservedHotbarSlot()) { FocusReservedHotbarSlots(Keybinds.holdingModifierKey); } } public static bool CanSwapToReservedHotbarSlot() { if (!HUDPatcher.hasReservedItemSlotsAndEnabled) { return false; } bool flag = (bool)Traverse.Create((object)localPlayerController).Field("throwingObject").GetValue(); return !(PlayerPatcher.playerDataLocal.grabbingReservedItemInfo != null || localPlayerController.isGrabbingObjectAnimation || localPlayerController.quickMenuManager.isMenuOpen || localPlayerController.inSpecialInteractAnimation || flag) && !localPlayerController.isTypingChat && !localPlayerController.twoHanded && !localPlayerController.activatingItem && !localPlayerController.jetpackControls && !localPlayerController.disablingJetpackControls && !localPlayerController.inTerminalMenu && !localPlayerController.isPlayerDead && !(GetTimeSinceSwitchingSlots(localPlayerController) < 0.3f); } [HarmonyPatch(typeof(PlayerControllerB), "UpdateSpecialAnimationValue")] [HarmonyPostfix] public static void OnSpecialAnimationUpdate(bool specialAnimation, PlayerControllerB __instance) { if (HUDPatcher.hasReservedItemSlotsAndEnabled && !((Object)(object)__instance != (Object)(object)localPlayerController) && !specialAnimation && !ConfigSettings.toggleFocusReservedHotbar.Value && PlayerPatcher.playerDataLocal.currentItemSlotIsReserved != Keybinds.holdingModifierKey) { FocusReservedHotbarSlots(Keybinds.holdingModifierKey); } } public static void FocusReservedHotbarSlots(bool active) { if (!HUDPatcher.hasReservedItemSlotsAndEnabled || (reservedHotbarSize <= 0 && active) || PlayerPatcher.playerDataLocal.currentItemSlotIsReserved == active) { return; } ReservedPlayerData playerDataLocal = PlayerPatcher.playerDataLocal; indexInHotbar = Mathf.Clamp(indexInHotbar, 0, localPlayerController.ItemSlots.Length - 1); indexInHotbar = ((!playerDataLocal.IsReservedItemSlot(indexInHotbar)) ? indexInHotbar : 0); indexInReservedHotbar = Mathf.Clamp(indexInReservedHotbar, playerDataLocal.reservedHotbarStartIndex, playerDataLocal.reservedHotbarEndIndexExcluded - 1); int num = Mathf.Clamp(localPlayerController.currentItemSlot, 0, localPlayerController.ItemSlots.Length); int i = num; bool flag = active; if (flag && !playerDataLocal.IsReservedItemSlot(num)) { indexInHotbar = num; indexInHotbar = ((!playerDataLocal.IsReservedItemSlot(indexInHotbar)) ? indexInHotbar : 0); i = indexInReservedHotbar; if ((Object)(object)localPlayerController.ItemSlots[i] == (Object)null && playerDataLocal.GetNumHeldReservedItems() > 0) { for (i = playerDataLocal.reservedHotbarStartIndex; i < playerDataLocal.reservedHotbarEndIndexExcluded && !((Object)(object)localPlayerController.ItemSlots[i] != (Object)null); i++) { } } Plugin.Log("Focusing reserved hotbar slots. NewIndex: " + i + " OldIndex: " + num + " ReservedStartIndex: " + PlayerPatcher.playerDataLocal.reservedHotbarStartIndex); } else if (!flag && PlayerPatcher.playerDataLocal.IsReservedItemSlot(num)) { indexInReservedHotbar = Mathf.Clamp(num, playerDataLocal.reservedHotbarStartIndex, playerDataLocal.reservedHotbarEndIndexExcluded - 1); i = indexInHotbar; Plugin.Log("Unfocusing reserved hotbar slots. NewIndex: " + i + " OldIndex: " + num + " ReservedStartIndex: " + PlayerPatcher.playerDataLocal.reservedHotbarStartIndex); } if (i < 0) { Plugin.LogError("Swapping to hotbar slot: " + i + ". Maybe send these logs to Flip? :)"); } else if (i >= localPlayerController.ItemSlots.Length) { Plugin.LogError("Swapping to hotbar slot: " + i + " InventorySize: " + localPlayerController.ItemSlots.Length + ". Maybe send these logs to Flip? :)"); } SyncManager.SwapHotbarSlot(i); if (localPlayerController.currentItemSlot != i) { Plugin.LogWarning("OnFocusReservedHotbarSlots - New hotbar index does not match target hotbar index. Tried to swap to index: " + i + " Current index: " + localPlayerController.currentItemSlot + " Tried swapping to reserved hotbar: " + active); } } internal static bool IsItemSlotEmpty(string itemName, PlayerControllerB playerController) { if (!SyncManager.TryGetReservedItemInfo(itemName, out var info)) { return false; } return IsItemSlotEmpty(info, playerController); } internal static bool IsItemSlotEmpty(ReservedItemInfo itemInfo, PlayerControllerB playerController) { playerController = (((Object)(object)playerController == (Object)null) ? localPlayerController : playerController); if (reservedHotbarSize == 0) { return false; } ReservedPlayerData reservedPlayerData = PlayerPatcher.allPlayerData[playerController]; int num = reservedPlayerData.reservedHotbarStartIndex + itemInfo.reservedItemIndex; return num >= reservedPlayerData.reservedHotbarStartIndex && num < reservedPlayerData.reservedHotbarStartIndex + reservedHotbarSize && (Object)(object)playerController.ItemSlots[num] == (Object)null; } public static bool TryGetHeldReservedObject(string itemName, PlayerControllerB playerController, ref GrabbableObject obj) { playerController = (((Object)(object)playerController == (Object)null) ? localPlayerController : playerController); if ((Object)(object)playerController == (Object)null || reservedHotbarSize == 0) { return false; } if (!SyncManager.TryGetReservedItemInfo(itemName, out var info)) { return false; } ReservedPlayerData reservedPlayerData = PlayerPatcher.allPlayerData[playerController]; int num = reservedPlayerData.reservedHotbarStartIndex + info.reservedItemIndex; obj = playerController.ItemSlots[num]; return (Object)(object)obj != (Object)null; } public static void ForceDisableItemMesh(GrabbableObject grabbableObject) { MeshRenderer[] componentsInChildren = ((Component)grabbableObject).GetComponentsInChildren<MeshRenderer>(); foreach (MeshRenderer val in componentsInChildren) { if (!((Object)val).name.Contains("ScanNode") && !((Component)val).gameObject.CompareTag("DoNotSet") && !((Component)val).gameObject.CompareTag("InteractTrigger")) { ((Renderer)val).enabled = false; } } } public static bool ReservedItemIsBeingGrabbed(GrabbableObject grabbableObject) { if ((Object)(object)grabbableObject == (Object)null) { return false; } foreach (ReservedPlayerData value in PlayerPatcher.allPlayerData.Values) { if ((Object)(object)grabbableObject == (Object)(object)value.grabbingReservedItem) { return true; } } return false; } public static float GetTimeSinceSwitchingSlots(PlayerControllerB playerController) { return (float)Traverse.Create((object)playerController).Field("timeSinceSwitchingSlots").GetValue(); } public static void SetTimeSinceSwitchingSlots(PlayerControllerB playerController, float value) { Traverse.Create((object)playerController).Field("timeSinceSwitchingSlots").SetValue((object)value); } public static void SetSpecialGrabAnimationBool(PlayerControllerB playerController, bool setTrue, GrabbableObject currentItem = null) { MethodInfo method = ((object)playerController).GetType().GetMethod("SetSpecialGrabAnimationBool", BindingFlags.Instance | BindingFlags.NonPublic); method.Invoke(playerController, new object[2] { setTrue, currentItem }); } public static void SwitchToItemSlot(PlayerControllerB playerController, int slot, GrabbableObject fillSlotWithItem = null) { MethodInfo method = ((object)playerController).GetType().GetMethod("SwitchToItemSlot", BindingFlags.Instance | BindingFlags.NonPublic); method.Invoke(playerController, new object[2] { slot, fillSlotWithItem }); SetTimeSinceSwitchingSlots(playerController, 0f); } } [HarmonyPatch] public static class PlayerPatcher { public static PlayerControllerB localPlayerController; public static int vanillaHotbarSize = -1; public static int hotbarSizeBeforeSync = -1; internal static Dictionary<PlayerControllerB, ReservedPlayerData> allPlayerData = new Dictionary<PlayerControllerB, ReservedPlayerData>(); public static bool spawned = false; public static bool isSynced = false; public static int INTERACTABLE_OBJECT_MASK { get; private set; } public static int reservedHotbarSize => SyncManager.numReservedItemSlots; internal static ReservedPlayerData playerDataLocal => (allPlayerData != null && (Object)(object)localPlayerController != (Object)null && allPlayerData.ContainsKey(localPlayerController)) ? allPlayerData[localPlayerController] : null; [HarmonyPatch(typeof(StartOfRound), "Awake")] [HarmonyPrefix] public static void InitSession(StartOfRound __instance) { localPlayerController = null; vanillaHotbarSize = -1; ReservedItemPatcher.indexInHotbar = 0; ReservedItemPatcher.indexInReservedHotbar = -1; Keybinds.holdingModifierKey = false; allPlayerData.Clear(); isSynced = false; spawned = false; } [HarmonyPatch(typeof(PlayerControllerB), "Awake")] [HarmonyPostfix] public static void InitializePlayerController(PlayerControllerB __instance) { if (vanillaHotbarSize == -1) { vanillaHotbarSize = __instance.ItemSlots.Length; } } [HarmonyPatch(typeof(PlayerControllerB), "Start")] [HarmonyPostfix] public static void InitializePlayerControllerLate(PlayerControllerB __instance) { allPlayerData.Add(__instance, new ReservedPlayerData { playerController = __instance, hotbarSize = __instance.ItemSlots.Length, reservedHotbarStartIndex = __instance.ItemSlots.Length }); } [HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")] [HarmonyPostfix] public static void OnLocalPlayerConnect(PlayerControllerB __instance) { localPlayerController = __instance; INTERACTABLE_OBJECT_MASK = (int)Traverse.Create((object)__instance).Field("interactableObjectsMask").GetValue(); ((MonoBehaviour)__instance).StartCoroutine(UpdateHotbarSlotsAfterFirstSpawnAnimation()); } private static IEnumerator UpdateHotbarSlotsAfterFirstSpawnAnimation() { yield return (object)new WaitForSeconds(3f); spawned = true; hotbarSizeBeforeSync = localPlayerController.ItemSlots.Length; if (!isSynced && (SyncManager.isSynced || SyncManager.canUseModDisabledOnHost)) { OnSyncedWithServer(); } } [HarmonyPatch(typeof(PlayerControllerB), "LateUpdate")] [HarmonyPostfix] public static void OnUpdate(PlayerControllerB __instance) { if (!spawned) { return; } if (SyncManager.isSynced && !isSynced) { OnSyncedWithServer(); } ReservedPlayerData reservedPlayerData = allPlayerData[__instance]; if ((!isSynced && (!SyncManager.canUseModDisabledOnHost || (Object)(object)__instance != (Object)(object)localPlayerController)) || reservedHotbarSize <= 0 || reservedPlayerData.hotbarSize == __instance.ItemSlots.Length) { return; } Plugin.Log("On update inventory size for player: " + ((Object)__instance).name + " - Old hotbar size: " + reservedPlayerData.hotbarSize + " - New hotbar size: " + __instance.ItemSlots.Length); reservedPlayerData.hotbarSize = __instance.ItemSlots.Length; int num = -1; if ((Object)(object)__instance == (Object)(object)localPlayerController) { if (HUDPatcher.reservedItemSlots != null && HUDPatcher.reservedItemSlots.Count > 0) { num = Array.IndexOf(HUDManager.Instance.itemSlotIconFrames, HUDPatcher.reservedItemSlots[0]); Plugin.Log("OnUpdateInventorySize A for player: " + ((Object)__instance).name + " NewReservedItemsStartIndex: " + num); } if (num == -1) { for (int i = 0; i < HUDManager.Instance.itemSlotIconFrames.Length; i++) { if (((Object)HUDManager.Instance.itemSlotIconFrames[i]).name.ToLower().Contains("reserved")) { num = i; Plugin.Log("OnUpdateInventorySize B for player: " + ((Object)__instance).name + " NewReservedItemsStartIndex: " + num); break; } } } } if (num == -1) { num = reservedPlayerData.reservedHotbarStartIndex; Plugin.Log("OnUpdateInventorySize C for player: " + ((Object)__instance).name + " NewReservedItemsStartIndex: " + num); } if (num == -1) { num = vanillaHotbarSize; Plugin.Log("OnUpdateInventorySize D for player: " + ((Object)__instance).name + " NewReservedItemsStartIndex: " + num); } reservedPlayerData.reservedHotbarStartIndex = num; if (reservedPlayerData.reservedHotbarStartIndex < 0) { Plugin.LogError("Set new reserved start index to slot: " + reservedPlayerData.reservedHotbarStartIndex + " . Maybe share these logs with Flip? :)"); } if (reservedPlayerData.reservedHotbarEndIndexExcluded - 1 >= reservedPlayerData.playerController.ItemSlots.Length) { Plugin.LogError("Set new reserved start index to slot: " + reservedPlayerData.reservedHotbarStartIndex + " Last reserved slot index: " + (reservedPlayerData.reservedHotbarEndIndexExcluded - 1) + " Inventory size: " + reservedPlayerData.playerController.ItemSlots.Length + ". Maybe share these logs with Flip? :)"); } if ((Object)(object)__instance == (Object)(object)localPlayerController) { HUDPatcher.UpdateHUD(); } } private static void OnSyncedWithServer() { isSynced = SyncManager.isSynced; int num = hotbarSizeBeforeSync + reservedHotbarSize; Plugin.Log("Finalizing sync with server. New hotbar size: " + num); PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts; foreach (PlayerControllerB val in allPlayerScripts) { allPlayerData[val].reservedHotbarStartIndex = hotbarSizeBeforeSync; if (num != val.ItemSlots.Length) { Array.Resize(ref val.ItemSlots, num); } allPlayerData[val].hotbarSize = num; } if (HUDPatcher.reservedItemSlots != null && HUDPatcher.reservedItemSlots.Count == SyncManager.numReservedItemSlots && playerDataLocal.reservedHotbarStartIndex < HUDManager.Instance.itemSlotIconFrames.Length && (Object)(object)HUDPatcher.reservedItemSlots[0] == (Object)(object)HUDManager.Instance.itemSlotIconFrames[playerDataLocal.reservedHotbarStartIndex]) { return; } if (HUDPatcher.reservedItemSlots != null && HUDPatcher.reservedItemSlots.Count > 0) { List<Image> list = new List<Image>(HUDManager.Instance.itemSlotIconFrames); List<Image> list2 = new List<Image>(HUDManager.Instance.itemSlotIcons); for (int j = 0; j < HUDManager.Instance.itemSlotIconFrames.Length; j++) { Image val2 = HUDManager.Instance.itemSlotIconFrames[j]; Image item = HUDManager.Instance.itemSlotIcons[j]; if (((Object)val2).name.Contains("Reserved")) { list.Remove(val2); list2.Remove(item); } } HUDManager.Instance.itemSlotIconFrames = list.ToArray(); HUDManager.Instance.itemSlotIcons = list2.ToArray(); } HUDPatcher.AddNewHotbarSlotsHud(); } } } namespace ReservedItemSlotCore.Compatibility { public class AdvancedCompanyPatcher { public static bool Enabled => Plugin.IsModLoaded("com.potatoepet.AdvancedCompany"); } }
plugins/FlipMods-ReservedSprayPaintSlot/ReservedSprayPaintSlot.dll
Decompiled 10 months agousing System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using GameNetcodeStuff; using HarmonyLib; using ReservedItemSlotCore; using ReservedItemSlotCore.Networking; using ReservedItemSlotCore.Patches; using ReservedSprayPaintSlot.Config; 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("ReservedSprayPaintSlot")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("ReservedSprayPaintSlot")] [assembly: AssemblyCopyright("Copyright © 2023")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("d5fcfd75-740b-418d-b185-a0bbdea6fa40")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("1.0.0.0")] namespace ReservedSprayPaintSlot { [BepInPlugin("FlipMods.ReservedSprayPaintSlot", "ReservedSprayPaintSlot", "1.0.7")] [BepInDependency(/*Could not decode attribute arguments.*/)] internal class Plugin : BaseUnityPlugin { public static Plugin instance; private Harmony _harmony; public static ReservedItemInfo sprayPaintInfo = new ReservedItemInfo("Spray paint", 30, true, true, false, false); private void Awake() { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Expected O, but got Unknown instance = this; ConfigSettings.BindConfigSettings(); _harmony = new Harmony("ReservedSprayPaintSlot"); _harmony.PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"ReservedSprayPaintSlot loaded"); } public static void Log(string message) { ((BaseUnityPlugin)instance).Logger.LogInfo((object)message); } } public static class PluginInfo { public const string PLUGIN_GUID = "FlipMods.ReservedSprayPaintSlot"; public const string PLUGIN_NAME = "ReservedSprayPaintSlot"; public const string PLUGIN_VERSION = "1.0.7"; } } namespace ReservedSprayPaintSlot.Patches { [HarmonyPatch] internal static class Patcher { private static Vector3 playerWaistPositionOffset = new Vector3(0.26f, -0.05f, 0.2f); private static Vector3 playerWaistRotationOffset = new Vector3(-105f, 0f, 0f); public static PlayerControllerB localPlayerController => PlayerPatcher.localPlayerController; public static PlayerControllerB GetPreviousPlayerHeldBy(SprayPaintItem sprayPaintItem) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown return (PlayerControllerB)Traverse.Create((object)sprayPaintItem).Field("previousPlayerHeldBy").GetValue(); } public static SprayPaintItem GetMainSprayPaint(PlayerControllerB playerController) { return GetCurrentlySelectedSprayPaint(playerController) ?? GetReservedSprayPaint(playerController); } public static SprayPaintItem GetReservedSprayPaint(PlayerControllerB playerController) { ReservedPlayerData value; return (SprayPaintItem)((SyncManager.syncReservedItemsList.Contains(Plugin.sprayPaintInfo) && PlayerPatcher.allPlayerData.TryGetValue(playerController, out value)) ? /*isinst with value type is only supported in some contexts*/: null); } public static SprayPaintItem GetCurrentlySelectedSprayPaint(PlayerControllerB playerController) { return (SprayPaintItem)((playerController.currentItemSlot >= 0 && playerController.currentItemSlot < playerController.ItemSlots.Length) ? /*isinst with value type is only supported in some contexts*/: null); } [HarmonyPatch(typeof(SprayPaintItem), "PocketItem")] [HarmonyPostfix] public static void OnPocketSprayPaintLocal(SprayPaintItem __instance) { if ((Object)(object)((GrabbableObject)__instance).playerHeldBy == (Object)null) { return; } MeshRenderer[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<MeshRenderer>(); foreach (MeshRenderer val in componentsInChildren) { if (!((Object)val).name.Contains("ScanNode") && !((Component)val).gameObject.CompareTag("DoNotSet") && !((Component)val).gameObject.CompareTag("InteractTrigger")) { ((Component)val).gameObject.layer = (((Object)(object)((GrabbableObject)__instance).playerHeldBy == (Object)(object)localPlayerController) ? 23 : 6); } } if ((Object)(object)__instance == (Object)(object)GetReservedSprayPaint(((GrabbableObject)__instance).playerHeldBy)) { ((GrabbableObject)__instance).parentObject = ((GrabbableObject)__instance).playerHeldBy.lowerSpine.parent; } } [HarmonyPatch(typeof(SprayPaintItem), "EquipItem")] [HarmonyPostfix] public static void OnEquipSprayPaint(SprayPaintItem __instance) { if ((Object)(object)((GrabbableObject)__instance).playerHeldBy == (Object)null) { return; } MeshRenderer[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<MeshRenderer>(); foreach (MeshRenderer val in componentsInChildren) { if (!((Object)val).name.Contains("ScanNode") && !((Component)val).gameObject.CompareTag("DoNotSet") && !((Component)val).gameObject.CompareTag("InteractTrigger")) { ((Component)val).gameObject.layer = 6; } } ((GrabbableObject)__instance).parentObject = (((Object)(object)((GrabbableObject)__instance).playerHeldBy == (Object)(object)localPlayerController) ? ((GrabbableObject)__instance).playerHeldBy.localItemHolder : ((GrabbableObject)__instance).playerHeldBy.serverItemHolder); } [HarmonyPatch(typeof(SprayPaintItem), "DiscardItem")] [HarmonyPostfix] public static void ResetLayerAfterDiscard(SprayPaintItem __instance) { MeshRenderer[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<MeshRenderer>(); foreach (MeshRenderer val in componentsInChildren) { if (!((Object)val).name.Contains("ScanNode") && !((Component)val).gameObject.CompareTag("DoNotSet") && !((Component)val).gameObject.CompareTag("InteractTrigger")) { ((Component)val).gameObject.layer = 6; } } } [HarmonyPatch(typeof(GrabbableObject), "LateUpdate")] [HarmonyPostfix] public static void SetPositionOffset(GrabbableObject __instance) { //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_009d: 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_00ac: Unknown result type (might be due to invalid IL or missing references) if (__instance is SprayPaintItem && (Object)(object)__instance.playerHeldBy != (Object)null && (Object)(object)__instance.parentObject != (Object)null && __instance.isPocketed && (Object)(object)__instance == (Object)(object)GetReservedSprayPaint(__instance.playerHeldBy) && (Object)(object)__instance != (Object)(object)GetCurrentlySelectedSprayPaint(__instance.playerHeldBy)) { Transform transform = ((Component)__instance.parentObject).transform; ((Component)__instance).transform.rotation = ((Component)__instance.parentObject).transform.rotation * Quaternion.Euler(playerWaistRotationOffset); ((Component)__instance).transform.position = transform.position + transform.rotation * playerWaistPositionOffset; } } [HarmonyPatch(typeof(GrabbableObject), "EnableItemMeshes")] [HarmonyPrefix] public static void OnEnableItemMeshes(ref bool enable, GrabbableObject __instance) { if (__instance is SprayPaintItem && (Object)(object)__instance.playerHeldBy != (Object)null && (Object)(object)__instance == (Object)(object)GetReservedSprayPaint(__instance.playerHeldBy) && !ConfigSettings.hideSprayPaintMeshWaist.Value && !ReservedItemPatcher.ReservedItemIsBeingGrabbed(__instance) && !ReservedItemPatcher.ReservedItemIsBeingGrabbed(__instance)) { enable = true; } } } [HarmonyPatch] public class SprayPaintTweaks { public static float GetSprayCanTankValue(SprayPaintItem sprayPaintItem) { return (float)Traverse.Create((object)sprayPaintItem).Field("sprayCanTank").GetValue(); } public static void SetSprayCanTankValue(SprayPaintItem sprayPaintItem, float value) { Traverse.Create((object)sprayPaintItem).Field("sprayCanTank").SetValue((object)value); } [HarmonyPatch(typeof(SprayPaintItem), "Start")] [HarmonyPrefix] public static void InitSprayPaint(SprayPaintItem __instance) { SetSprayCanTankValue(__instance, ConfigSettings.sprayPaintCapacityMultiplier.Value); } [HarmonyPatch(typeof(SprayPaintItem), "LoadItemSaveData")] [HarmonyPostfix] public static void OnLoadValues(int saveData, SprayPaintItem __instance) { float value = Mathf.Clamp(GetSprayCanTankValue(__instance) * ConfigSettings.sprayPaintCapacityMultiplier.Value, 0f, ConfigSettings.sprayPaintCapacityMultiplier.Value); SetSprayCanTankValue(__instance, value); Plugin.Log("Loading spraypaint save data. Remaining capacity: " + value); } [HarmonyPatch(typeof(SprayPaintItem), "GetItemDataToSave")] [HarmonyPostfix] public static void OnSaveValues(ref int __result, SprayPaintItem __instance) { __result = (int)Mathf.Clamp((float)__result / ConfigSettings.sprayPaintCapacityMultiplier.Value, 0f, 100f); } } } namespace ReservedSprayPaintSlot.Config { public static class ConfigSettings { public static ConfigEntry<bool> hideSprayPaintMeshWaist; public static ConfigEntry<float> sprayPaintCapacityMultiplier; public static void BindConfigSettings() { Plugin.Log("BindingConfigs"); hideSprayPaintMeshWaist = ((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Client", "HideSprayPaintOnWaist", false, "Hides the spray paint mesh while on your waist."); sprayPaintCapacityMultiplier = ((BaseUnityPlugin)Plugin.instance).Config.Bind<float>("Client", "SprayPaintCapacityMultiplier", 10f, "Extends the max capacity of spraypaint cans by this multiplier. This setting will soon be host only, and will sync with all non-host clients."); sprayPaintCapacityMultiplier.Value = Mathf.Max(sprayPaintCapacityMultiplier.Value, 0f); } } }
plugins/FlipMods-ReservedWalkieSlot/ReservedWalkieSlot.dll
Decompiled 10 months agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using GameNetcodeStuff; using HarmonyLib; using LethalCompanyInputUtils.Api; using ReservedItemSlotCore; using ReservedItemSlotCore.Networking; using ReservedItemSlotCore.Patches; using ReservedWalkieSlot.Patches; using Unity.Netcode; using UnityEngine; using UnityEngine.InputSystem; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("ReservedWalkieSlot")] [assembly: AssemblyDescription("Mod made by flipf17")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("ReservedWalkieSlot")] [assembly: AssemblyCopyright("Copyright © 2023")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("c15c320f-d8fc-4f1c-be3c-f2d2ffc41edd")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("1.0.0.0")] namespace ReservedWalkieSlot { public static class ConfigSettings { public static ConfigEntry<string> activateWalkieKey; public static ConfigEntry<bool> hideWalkieMeshShoulder; public static string activateWalkieDisplayName; public static Dictionary<string, ConfigEntryBase> currentConfigEntries = new Dictionary<string, ConfigEntryBase>(); public static void BindConfigSettings() { Plugin.Log("BindingConfigs"); activateWalkieKey = ((BaseUnityPlugin)Plugin.instance).Config.Bind<string>("ReservedWalkieSlot", "ActivateWalkieKey", "<Keyboard>/x", "This setting will be ignored if InputUtils is installed and enabled. (I recommend running InputUtils to edit keybinds in the in-game settings)"); hideWalkieMeshShoulder = ((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("ReservedWalkieSlot", "HideWalkieOnShoulder", false, "Hides the walkie mesh while on your shoulder. Only applies in scenarios where you can view your player in third person."); activateWalkieDisplayName = GetDisplayName(activateWalkieKey.Value); currentConfigEntries.Add(((ConfigEntryBase)activateWalkieKey).Definition.Key, (ConfigEntryBase)(object)activateWalkieKey); currentConfigEntries.Add(((ConfigEntryBase)hideWalkieMeshShoulder).Definition.Key, (ConfigEntryBase)(object)hideWalkieMeshShoulder); TryRemoveOldConfigSettings(); } public static string GetDisplayName(string key) { key = key.Replace("<Keyboard>/", ""); key = key.Replace("<Mouse>/", ""); string text = key; text = text.Replace("leftAlt", "Alt"); text = text.Replace("rightAlt", "Alt"); text = text.Replace("leftCtrl", "Ctrl"); text = text.Replace("rightCtrl", "Ctrl"); text = text.Replace("leftShift", "Shift"); text = text.Replace("rightShift", "Shift"); text = text.Replace("leftButton", "LMB"); text = text.Replace("rightButton", "RMB"); return text.Replace("middleButton", "MMB"); } public static void TryRemoveOldConfigSettings() { HashSet<string> hashSet = new HashSet<string>(); HashSet<string> hashSet2 = new HashSet<string>(); foreach (ConfigEntryBase value in currentConfigEntries.Values) { hashSet.Add(value.Definition.Section); hashSet2.Add(value.Definition.Key); } try { Plugin.Log("Cleaning old config entries"); ConfigFile config = ((BaseUnityPlugin)Plugin.instance).Config; string configFilePath = config.ConfigFilePath; if (!File.Exists(configFilePath)) { return; } string text = File.ReadAllText(configFilePath); string[] array = File.ReadAllLines(configFilePath); string text2 = ""; for (int i = 0; i < array.Length; i++) { array[i] = array[i].Replace("\n", ""); if (array[i].Length <= 0) { continue; } if (array[i].StartsWith("[")) { if (text2 != "" && !hashSet.Contains(text2)) { text2 = "[" + text2 + "]"; int num = text.IndexOf(text2); int num2 = text.IndexOf(array[i]); text = text.Remove(num, num2 - num); } text2 = array[i].Replace("[", "").Replace("]", "").Trim(); } else { if (!(text2 != "")) { continue; } if (i <= array.Length - 4 && array[i].StartsWith("##")) { int j; for (j = 1; i + j < array.Length && array[i + j].Length > 3; j++) { } if (hashSet.Contains(text2)) { int num3 = array[i + j - 1].IndexOf("="); string item = array[i + j - 1].Substring(0, num3 - 1); if (!hashSet2.Contains(item)) { int num4 = text.IndexOf(array[i]); int num5 = text.IndexOf(array[i + j - 1]) + array[i + j - 1].Length; text = text.Remove(num4, num5 - num4); } } i += j - 1; } else if (array[i].Length > 3) { text = text.Replace(array[i], ""); } } } if (!hashSet.Contains(text2)) { text2 = "[" + text2 + "]"; int num6 = text.IndexOf(text2); text = text.Remove(num6, text.Length - num6); } while (text.Contains("\n\n\n")) { text = text.Replace("\n\n\n", "\n\n"); } File.WriteAllText(configFilePath, text); config.Reload(); } catch { } } } [BepInPlugin("FlipMods.ReservedWalkieSlot", "ReservedWalkieSlot", "1.6.2")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] internal class Plugin : BaseUnityPlugin { public static Plugin instance; private Harmony _harmony; private static ManualLogSource logger; public static ReservedItemInfo walkieInfo = new ReservedItemInfo("Walkie-talkie", 100, false, false, false, false); private void Awake() { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Expected O, but got Unknown instance = this; CreateCustomLogger(); ConfigSettings.BindConfigSettings(); _harmony = new Harmony("ReservedWalkieSlot"); PatchAll(); Log("ReservedWalkieSlot loaded"); } private void PatchAll() { IEnumerable<Type> enumerable; try { enumerable = Assembly.GetExecutingAssembly().GetTypes(); } catch (ReflectionTypeLoadException ex) { enumerable = ex.Types.Where((Type t) => t != null); } foreach (Type item in enumerable) { _harmony.PatchAll(item); } } private void CreateCustomLogger() { try { logger = Logger.CreateLogSource($"{((BaseUnityPlugin)this).Info.Metadata.Name}-{((BaseUnityPlugin)this).Info.Metadata.Version}"); } catch { logger = ((BaseUnityPlugin)this).Logger; } } public static void Log(string message) { logger.LogInfo((object)message); } public static void LogError(string message) { logger.LogError((object)message); } public static void LogWarning(string message) { logger.LogWarning((object)message); } public static bool IsModLoaded(string guid) { return Chainloader.PluginInfos.ContainsKey(guid); } } public static class PluginInfo { public const string PLUGIN_GUID = "FlipMods.ReservedWalkieSlot"; public const string PLUGIN_NAME = "ReservedWalkieSlot"; public const string PLUGIN_VERSION = "1.6.2"; } } namespace ReservedWalkieSlot.Input { internal class InputUtilsCompat { internal static InputActionAsset Asset => IngameKeybinds.GetAsset(); internal static bool Enabled => Plugin.IsModLoaded("com.rune580.LethalCompanyInputUtils"); public static InputAction ActivateWalkieHotkey => IngameKeybinds.Instance.ActivateWalkieHotkey; } internal class IngameKeybinds : LcInputActions { internal static IngameKeybinds Instance = new IngameKeybinds(); [InputAction("<Keyboard>/x", Name = "[ReservedItemSlots]\nActivate walkie")] public InputAction ActivateWalkieHotkey { get; set; } internal static InputActionAsset GetAsset() { return ((LcInputActions)Instance).Asset; } } [HarmonyPatch] internal static class Keybinds { public static InputActionAsset Asset; public static InputActionMap ActionMap; private static InputAction ActivateWalkieAction; public static PlayerControllerB localPlayerController => StartOfRound.Instance?.localPlayerController; [HarmonyPatch(typeof(PreInitSceneScript), "Awake")] [HarmonyPrefix] public static void AddToKeybindMenu() { //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Expected O, but got Unknown //IL_0025: 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) Plugin.Log("Initializing hotkeys."); if (InputUtilsCompat.Enabled) { Asset = InputUtilsCompat.Asset; ActionMap = Asset.actionMaps[0]; ActivateWalkieAction = InputUtilsCompat.ActivateWalkieHotkey; } else { Asset = ScriptableObject.CreateInstance<InputActionAsset>(); ActionMap = new InputActionMap("ReservedItemSlots"); InputActionSetupExtensions.AddActionMap(Asset, ActionMap); ActivateWalkieAction = InputActionSetupExtensions.AddAction(ActionMap, "ReservedItemSlots.ActivateWalkie", (InputActionType)0, ConfigSettings.activateWalkieKey.Value, (string)null, (string)null, (string)null, (string)null); } } [HarmonyPatch(typeof(StartOfRound), "OnEnable")] [HarmonyPostfix] public static void OnEnable() { Asset.Enable(); ActivateWalkieAction.performed += OnPressWalkieButtonPerformed; ActivateWalkieAction.canceled += OnReleaseWalkieButtonPerformed; } [HarmonyPatch(typeof(StartOfRound), "OnDisable")] [HarmonyPostfix] public static void OnDisable() { Asset.Disable(); ActivateWalkieAction.performed -= OnPressWalkieButtonPerformed; ActivateWalkieAction.canceled -= OnReleaseWalkieButtonPerformed; } private static void OnPressWalkieButtonPerformed(CallbackContext context) { if ((Object)(object)localPlayerController == (Object)null || !localPlayerController.isPlayerControlled || (((NetworkBehaviour)localPlayerController).IsServer && !localPlayerController.isHostPlayerObject)) { return; } WalkieTalkie mainWalkie = WalkiePatcher.GetMainWalkie(localPlayerController); if (((CallbackContext)(ref context)).performed && !((Object)(object)mainWalkie == (Object)null) && ((GrabbableObject)mainWalkie).isBeingUsed && !ShipBuildModeManager.Instance.InBuildMode) { float num = (float)Traverse.Create((object)localPlayerController).Field("timeSinceSwitchingSlots").GetValue(); if (!(num < 0.075f)) { Plugin.Log("Speaking into walkie"); ((GrabbableObject)mainWalkie).UseItemOnClient(true); Traverse.Create((object)localPlayerController).Field("timeSinceSwitchingSlots").SetValue((object)0); } } } private static void OnReleaseWalkieButtonPerformed(CallbackContext context) { if (!((Object)(object)localPlayerController == (Object)null) && localPlayerController.isPlayerControlled && (!((NetworkBehaviour)localPlayerController).IsServer || localPlayerController.isHostPlayerObject)) { WalkieTalkie mainWalkie = WalkiePatcher.GetMainWalkie(localPlayerController); if (((CallbackContext)(ref context)).canceled && !((Object)(object)mainWalkie == (Object)null)) { Plugin.Log("Not talking into walkie"); ((GrabbableObject)mainWalkie).UseItemOnClient(false); } } } } } namespace ReservedWalkieSlot.Patches { [HarmonyPatch] public class MaskedEnemyPatcher { public static Dictionary<MaskedPlayerEnemy, GameObject> heldWalkiesByEnemy = new Dictionary<MaskedPlayerEnemy, GameObject>(); public static HashSet<MaskedPlayerEnemy> spawnedEnemies = new HashSet<MaskedPlayerEnemy>(); [HarmonyPatch(typeof(MaskedPlayerEnemy), "OnDestroy")] [HarmonyPrefix] public static void OnDestroy(MaskedPlayerEnemy __instance) { if (heldWalkiesByEnemy.TryGetValue(__instance, out var value)) { Plugin.LogWarning("Destroying walkie. Enemy destroyed."); Object.DestroyImmediate((Object)(object)value); spawnedEnemies.Remove(__instance); } heldWalkiesByEnemy.Remove(__instance); } [HarmonyPatch(typeof(MaskedPlayerEnemy), "LateUpdate")] [HarmonyPostfix] public static void ShowWalkieOnEnemy(MaskedPlayerEnemy __instance) { //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Expected O, but got Unknown //IL_020b: Unknown result type (might be due to invalid IL or missing references) //IL_0210: Unknown result type (might be due to invalid IL or missing references) //IL_0215: Unknown result type (might be due to invalid IL or missing references) //IL_021a: Unknown result type (might be due to invalid IL or missing references) //IL_022d: Unknown result type (might be due to invalid IL or missing references) //IL_0234: Unknown result type (might be due to invalid IL or missing references) //IL_0239: Unknown result type (might be due to invalid IL or missing references) //IL_023e: Unknown result type (might be due to invalid IL or missing references) //IL_0243: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: 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_013c: Unknown result type (might be due to invalid IL or missing references) //IL_0148: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) if (!spawnedEnemies.Contains(__instance) && SyncManager.syncReservedItemsList.Contains(Plugin.walkieInfo) && !((EnemyAI)__instance).isEnemyDead && !heldWalkiesByEnemy.ContainsKey(__instance) && (Object)(object)__instance.mimickingPlayer != (Object)null && PlayerPatcher.allPlayerData.TryGetValue(__instance.mimickingPlayer, out var value)) { spawnedEnemies.Add(__instance); WalkieTalkie reservedWalkie = WalkiePatcher.GetReservedWalkie(value.playerController); if ((Object)(object)reservedWalkie != (Object)null) { Plugin.LogWarning("OnMaskedEnemySpawn - MimickingPlayer: " + ((Object)value.playerController).name + " - Spawning walkie object on enemy."); GameObject val = new GameObject("ReservedWalkie [MaskedEnemy]"); Light[] componentsInChildren = ((Component)reservedWalkie).GetComponentsInChildren<Light>(); MeshRenderer mainObjectRenderer = ((GrabbableObject)reservedWalkie).mainObjectRenderer; Light[] array = componentsInChildren; foreach (Light val2 in array) { Light component = Object.Instantiate<GameObject>(((Component)val2).gameObject, ((Component)val2).transform.localPosition, ((Component)val2).transform.localRotation, val.transform).GetComponent<Light>(); ((Behaviour)component).enabled = true; ((Component)component).gameObject.layer = 6; } MeshRenderer component2 = Object.Instantiate<GameObject>(((Component)mainObjectRenderer).gameObject, ((Component)mainObjectRenderer).transform.localPosition, ((Component)mainObjectRenderer).transform.localRotation, val.transform).GetComponent<MeshRenderer>(); ((Renderer)component2).enabled = true; ((Component)component2).gameObject.layer = 6; val.transform.localScale = ((Component)reservedWalkie).transform.localScale; heldWalkiesByEnemy.Add(__instance, val); } } if (heldWalkiesByEnemy.TryGetValue(__instance, out var value2)) { if (((EnemyAI)__instance).isEnemyDead) { Plugin.LogWarning("Destroying walkie. Enemy dead."); Object.DestroyImmediate((Object)(object)value2); spawnedEnemies.Remove(__instance); heldWalkiesByEnemy.Remove(__instance); } else { Transform parent = ((EnemyAI)__instance).eye.parent.parent; value2.transform.rotation = parent.rotation * Quaternion.Euler(WalkiePatcher.playerShoulderRotationOffset); value2.transform.position = parent.position + parent.rotation * WalkiePatcher.playerShoulderPositionOffset; } } } } [HarmonyPatch(typeof(ShipBuildModeManager), "PlayerMeetsConditionsToBuild")] public class PlayerMeetsConditionsToBuildPatcher { private static bool activatingWalkie; private static PlayerControllerB localPlayerController => StartOfRound.Instance?.localPlayerController; public static void Prefix(ShipBuildModeManager __instance) { if (!((Object)(object)localPlayerController == (Object)null)) { activatingWalkie = localPlayerController.activatingItem; WalkieTalkie mainWalkie = WalkiePatcher.GetMainWalkie(localPlayerController); if (!((Object)(object)mainWalkie == (Object)null) && !((Object)(object)((GrabbableObject)mainWalkie).playerHeldBy == (Object)null) && !((Object)(object)((GrabbableObject)mainWalkie).playerHeldBy != (Object)(object)localPlayerController) && localPlayerController.activatingItem && mainWalkie.speakingIntoWalkieTalkie) { localPlayerController.activatingItem = false; } } } public static void Postfix(ShipBuildModeManager __instance) { if (!((Object)(object)localPlayerController == (Object)null)) { localPlayerController.activatingItem = activatingWalkie; } } } [HarmonyPatch] public static class WalkiePatcher { public static Vector3 localPlayerShoulderPositionOffset = new Vector3(0.125f, 0.4f, 0.125f); public static Vector3 playerShoulderPositionOffset = new Vector3(0.15f, -0.05f, 0.25f); public static Vector3 playerShoulderRotationOffset = new Vector3(0f, 270f, 100f); public static PlayerControllerB localPlayerController => PlayerPatcher.localPlayerController; public static WalkieTalkie GetMainWalkie(PlayerControllerB playerController) { return GetCurrentlySelectedWalkie(playerController) ?? GetReservedWalkie(playerController); } public static WalkieTalkie GetReservedWalkie(PlayerControllerB playerController) { ReservedPlayerData value; return (WalkieTalkie)((SyncManager.syncReservedItemsList.Contains(Plugin.walkieInfo) && PlayerPatcher.allPlayerData.TryGetValue(playerController, out value)) ? /*isinst with value type is only supported in some contexts*/: null); } public static WalkieTalkie GetCurrentlySelectedWalkie(PlayerControllerB playerController) { return (WalkieTalkie)((playerController.currentItemSlot >= 0 && playerController.currentItemSlot < playerController.ItemSlots.Length) ? /*isinst with value type is only supported in some contexts*/: null); } [HarmonyPatch(typeof(WalkieTalkie), "PocketItem")] [HarmonyPostfix] public static void OnPocketWalkie(WalkieTalkie __instance) { if ((Object)(object)((GrabbableObject)__instance).playerHeldBy == (Object)null) { return; } Renderer[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<Renderer>(); foreach (Renderer val in componentsInChildren) { if (!((Object)val).name.Contains("ScanNode") && !((Component)val).gameObject.CompareTag("DoNotSet") && !((Component)val).gameObject.CompareTag("InteractTrigger")) { ((Component)val).gameObject.layer = (((Object)(object)((GrabbableObject)__instance).playerHeldBy == (Object)(object)localPlayerController) ? 23 : 6); } } ((GrabbableObject)__instance).parentObject = ((Component)((GrabbableObject)__instance).playerHeldBy.playerBadgeMesh).transform.parent; } [HarmonyPatch(typeof(WalkieTalkie), "EquipItem")] [HarmonyPostfix] public static void OnEquipWalkie(WalkieTalkie __instance) { if ((Object)(object)((GrabbableObject)__instance).playerHeldBy == (Object)null) { return; } Renderer[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<Renderer>(); foreach (Renderer val in componentsInChildren) { if (!((Object)val).name.Contains("ScanNode") && !((Component)val).gameObject.CompareTag("DoNotSet") && !((Component)val).gameObject.CompareTag("InteractTrigger")) { ((Component)val).gameObject.layer = 6; } } ((GrabbableObject)__instance).parentObject = (((Object)(object)((GrabbableObject)__instance).playerHeldBy == (Object)(object)localPlayerController) ? ((GrabbableObject)__instance).playerHeldBy.localItemHolder : ((GrabbableObject)__instance).playerHeldBy.serverItemHolder); } [HarmonyPatch(typeof(WalkieTalkie), "DiscardItem")] [HarmonyPostfix] public static void OnDiscardWalkie(WalkieTalkie __instance) { Renderer[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<Renderer>(); foreach (Renderer val in componentsInChildren) { if (!((Object)val).name.Contains("ScanNode") && !((Component)val).gameObject.CompareTag("DoNotSet") && !((Component)val).gameObject.CompareTag("InteractTrigger")) { ((Component)val).gameObject.layer = 6; } } } [HarmonyPatch(typeof(GrabbableObject), "LateUpdate")] [HarmonyPostfix] public static void SetPositionOffset(GrabbableObject __instance) { //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_009d: 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_00ac: Unknown result type (might be due to invalid IL or missing references) if (__instance is WalkieTalkie && (Object)(object)__instance.playerHeldBy != (Object)null && (Object)(object)__instance.parentObject != (Object)null && __instance.isPocketed && (Object)(object)__instance == (Object)(object)GetReservedWalkie(__instance.playerHeldBy) && (Object)(object)__instance != (Object)(object)GetCurrentlySelectedWalkie(__instance.playerHeldBy)) { Transform transform = ((Component)__instance.parentObject).transform; ((Component)__instance).transform.rotation = ((Component)__instance.parentObject).transform.rotation * Quaternion.Euler(playerShoulderRotationOffset); ((Component)__instance).transform.position = transform.position + transform.rotation * playerShoulderPositionOffset; } } [HarmonyPatch(typeof(GrabbableObject), "EnableItemMeshes")] [HarmonyPrefix] public static void OnEnableItemMeshes(ref bool enable, GrabbableObject __instance) { if (__instance is WalkieTalkie && (Object)(object)__instance.playerHeldBy != (Object)null && (Object)(object)__instance == (Object)(object)GetReservedWalkie(__instance.playerHeldBy) && !ConfigSettings.hideWalkieMeshShoulder.Value && !ReservedItemPatcher.ReservedItemIsBeingGrabbed(__instance)) { enable = true; } } } }
plugins/FlipMods-ReservedWeaponSlot/ReservedWeaponSlot.dll
Decompiled 10 months agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using GameNetcodeStuff; using HarmonyLib; using LethalCompanyInputUtils.Api; using ReservedItemSlotCore; using ReservedItemSlotCore.Networking; using ReservedItemSlotCore.Patches; using ReservedWeaponSlot.Input; using ReservedWeaponSlot.Patches; using Unity.Netcode; using UnityEngine; using UnityEngine.InputSystem; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("ReservedWeaponSlot")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("ReservedWeaponSlot")] [assembly: AssemblyCopyright("Copyright © 2023")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("5b723481-f5bd-43e5-9f47-26325095eea7")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("1.0.0.0")] namespace ReservedWeaponSlot { public static class ConfigSettings { public static ConfigEntry<bool> addSeparateSlotForMeleeWeapons; public static ConfigEntry<bool> disableReservedAmmoSlot; public static ConfigEntry<string> swapToWeaponSlotHotkey; public static ConfigEntry<bool> swapToWeaponSlotToggled; public static ConfigEntry<bool> hideWeaponMeshHolstered; public static ConfigEntry<bool> hideAmmoMeshHolstered; public static void BindConfigSettings() { Plugin.Log("BindingConfigs"); addSeparateSlotForMeleeWeapons = ((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Server", "AddSeparateSlotForMeleeWeapons", false, "[Host only] If true, melee weapons will have their own reserved slot."); disableReservedAmmoSlot = ((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Server", "DisableReservedAmmoSlot", false, "[Host only] Disables the reserved ammo slot. Will sync with clients."); swapToWeaponSlotHotkey = ((BaseUnityPlugin)Plugin.instance).Config.Bind<string>("Client", "SwapToWeaponSlotHotkey", "", "Format: \"<keyboard>/t\" to swap to weapon slot by pressing t. This option will be ignored if using InputUtils as the keybind can be set in the ingame keybinds menu."); swapToWeaponSlotToggled = ((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Client", "SwapToWeaponSlotToggled", true, "If true, swapping to weapon slot will be toggled rather than while held."); hideWeaponMeshHolstered = ((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Client", "HideWeaponOnPlayer", false, "[Not implemented yet] Hides the reserved weapon mesh while holstered. This should hide it in third person mods."); hideAmmoMeshHolstered = ((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Client", "HideAmmoOnPlayer", false, "[Not implemented yet] Hides the reserved ammo mesh while holstered. This should hide it in third person mods."); } } [BepInPlugin("FlipMods.ReservedWeaponSlot", "ReservedWeaponSlot", "1.0.8")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] internal class Plugin : BaseUnityPlugin { public static Plugin instance; private Harmony _harmony; private static ManualLogSource logger; private int meleeWeaponPriority = 70; public static ReservedItemInfo shotgunInfo = new ReservedItemInfo("Shotgun", 70, false, false, false, false); public static ReservedItemInfo zapGunInfo = new ReservedItemInfo("Zap gun", 70, false, false, false, false); public static ReservedItemInfo shovelInfo; public static ReservedItemInfo stopSignInfo; public static ReservedItemInfo yieldSignInfo; public static ReservedItemInfo stunGrenadeInfo = new ReservedItemInfo("Stun grenade", 70, false, false, false, false); public static ReservedItemInfo homemadeFlashbangInfo = new ReservedItemInfo("Homemade flashbang", 70, false, false, false, false); public static ReservedItemInfo rocketLauncherInfo = new ReservedItemInfo("Rocket Launcher", 70, false, false, false, false); public static ReservedItemInfo flareGunInfo = new ReservedItemInfo("Flaregun", 70, false, false, false, false); public static ReservedItemInfo toyGunInfo = new ReservedItemInfo("Revolver", 70, false, false, false, false); public static ReservedItemInfo toyHammerInfo; public static ReservedItemInfo goldenShovelInfo; public static ReservedItemInfo ammoInfo; public static ReservedItemInfo shotgunAmmoInfo; public static ReservedItemInfo flareGunAmmoInfo; private void Awake() { //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Expected O, but got Unknown //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Expected O, but got Unknown //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Expected O, but got Unknown //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Expected O, but got Unknown //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Expected O, but got Unknown //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Expected O, but got Unknown //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Expected O, but got Unknown //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Expected O, but got Unknown //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Expected O, but got Unknown instance = this; CreateCustomLogger(); ConfigSettings.BindConfigSettings(); meleeWeaponPriority = (ConfigSettings.addSeparateSlotForMeleeWeapons.Value ? 80 : 70); shovelInfo = new ReservedItemInfo("Shovel", meleeWeaponPriority, false, false, false, false); stopSignInfo = new ReservedItemInfo("Stop sign", meleeWeaponPriority, false, false, false, false); yieldSignInfo = new ReservedItemInfo("Yield sign", meleeWeaponPriority, false, false, false, false); toyHammerInfo = new ReservedItemInfo("Toy Hammer", meleeWeaponPriority, false, false, false, false); goldenShovelInfo = new ReservedItemInfo("Australium Shovel", meleeWeaponPriority, false, false, false, false); if (!ConfigSettings.disableReservedAmmoSlot.Value) { ammoInfo = new ReservedItemInfo("Ammo", -20, false, false, false, false); shotgunAmmoInfo = new ReservedItemInfo("Shells", -20, false, false, false, false); flareGunAmmoInfo = new ReservedItemInfo("Emergency Flare (ammo)", -20, false, false, false, false); } _harmony = new Harmony("ReservedWeaponSlot"); PatchAll(); Log("ReservedWeaponSlot loaded"); } private void PatchAll() { IEnumerable<Type> enumerable; try { enumerable = Assembly.GetExecutingAssembly().GetTypes(); } catch (ReflectionTypeLoadException ex) { enumerable = ex.Types.Where((Type t) => t != null); } foreach (Type item in enumerable) { _harmony.PatchAll(item); } } private void CreateCustomLogger() { try { logger = Logger.CreateLogSource($"{((BaseUnityPlugin)this).Info.Metadata.Name}-{((BaseUnityPlugin)this).Info.Metadata.Version}"); } catch { logger = ((BaseUnityPlugin)this).Logger; } } public static void Log(string message) { logger.LogInfo((object)message); } public static void LogError(string message) { logger.LogError((object)message); } public static void LogWarning(string message) { logger.LogWarning((object)message); } public static bool IsModLoaded(string guid) { return Chainloader.PluginInfos.ContainsKey(guid); } } public static class PluginInfo { public const string PLUGIN_GUID = "FlipMods.ReservedWeaponSlot"; public const string PLUGIN_NAME = "ReservedWeaponSlot"; public const string PLUGIN_VERSION = "1.0.8"; } } namespace ReservedWeaponSlot.Patches { [HarmonyPatch] internal static class Patcher { private static Vector3 playerWaistPositionOffset = new Vector3(0.26f, -0.05f, 0.2f); private static Vector3 playerWaistRotationOffset = new Vector3(-105f, 0f, 0f); public static PlayerControllerB localPlayerController => PlayerPatcher.localPlayerController; public static ReservedPlayerData localPlayerData => PlayerPatcher.playerDataLocal; public static int reservedWeaponSlotIndex => SyncManager.syncReservedItemsList.Contains(Plugin.shotgunInfo) ? (localPlayerData.reservedHotbarStartIndex + Plugin.shotgunInfo.reservedItemIndex) : (-1); public static PlayerControllerB GetPreviousPlayerHeldBy(GrabbableObject weaponItem) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown return (PlayerControllerB)Traverse.Create((object)weaponItem).Field("previousPlayerHeldBy").GetValue(); } public static GrabbableObject GetMainWeapon(PlayerControllerB playerController) { return GetCurrentlySelectedWeapon(playerController) ?? GetReservedWeapon(playerController); } public static GrabbableObject GetReservedWeapon(PlayerControllerB playerController) { ReservedPlayerData value; return (SyncManager.syncReservedItemsList.Contains(Plugin.shotgunInfo) && PlayerPatcher.allPlayerData.TryGetValue(playerController, out value)) ? value.GetReservedItem(Plugin.shotgunInfo) : null; } public static GrabbableObject GetCurrentlySelectedWeapon(PlayerControllerB playerController) { return (playerController.currentItemSlot < 0 || playerController.currentItemSlot >= playerController.ItemSlots.Length) ? null : ((playerController != null) ? playerController.ItemSlots[playerController.currentItemSlot] : null); } [HarmonyPatch(typeof(GrabbableObject), "PocketItem")] [HarmonyPostfix] public static void OnPocketWeaponLocal(GrabbableObject __instance) { if (!((Object)(object)__instance?.playerHeldBy == (Object)null) && !Plugin.shovelInfo.acceptedItemNames.Contains(__instance.itemProperties.itemName) && !Plugin.shotgunInfo.acceptedItemNames.Contains(__instance.itemProperties.itemName) && Plugin.shotgunAmmoInfo?.acceptedItemNames != null && Plugin.shotgunAmmoInfo.acceptedItemNames.Contains(__instance.itemProperties.itemName)) { } } [HarmonyPatch(typeof(GrabbableObject), "EquipItem")] [HarmonyPostfix] public static void OnEquipWeapon(GrabbableObject __instance) { if (!((Object)(object)__instance?.playerHeldBy == (Object)null) && (Plugin.shovelInfo.acceptedItemNames.Contains(__instance.itemProperties.itemName) || Plugin.shotgunInfo.acceptedItemNames.Contains(__instance.itemProperties.itemName) || (Plugin.shotgunAmmoInfo?.acceptedItemNames != null && Plugin.shotgunAmmoInfo.acceptedItemNames.Contains(__instance.itemProperties.itemName)))) { __instance.parentObject = (((Object)(object)__instance.playerHeldBy == (Object)(object)localPlayerController) ? __instance.playerHeldBy.localItemHolder : __instance.playerHeldBy.serverItemHolder); } } [HarmonyPatch(typeof(GrabbableObject), "DiscardItem")] [HarmonyPostfix] public static void ResetLayerAfterDiscard(GrabbableObject __instance) { } [HarmonyPatch(typeof(PlayerControllerB), "ScrollMouse_performed")] [HarmonyPrefix] public static bool PreventScrollHoldingWeaponModifier(PlayerControllerB __instance) { if ((Object)(object)__instance == (Object)(object)localPlayerController && reservedWeaponSlotIndex != -1 && localPlayerData.currentItemSlot == reservedWeaponSlotIndex && Keybinds.holdingWeaponModifier && !ConfigSettings.swapToWeaponSlotToggled.Value) { return false; } return true; } } } namespace ReservedWeaponSlot.Input { internal class IngameKeybinds : LcInputActions { internal static IngameKeybinds Instance = new IngameKeybinds(); [InputAction("", Name = "[ReservedItemSlots]\nToggle weapon slot")] public InputAction ToggleWeaponSlotHotkey { get; set; } internal static InputActionAsset GetAsset() { return ((LcInputActions)Instance).Asset; } } internal class InputUtilsCompat { internal static InputActionAsset Asset => IngameKeybinds.GetAsset(); internal static bool Enabled => Plugin.IsModLoaded("com.rune580.LethalCompanyInputUtils"); public static InputAction ToggleWeaponHotkey => IngameKeybinds.Instance.ToggleWeaponSlotHotkey; } [HarmonyPatch] internal static class Keybinds { public static InputActionAsset Asset; public static InputActionMap ActionMap; private static InputAction ToggleWeaponSlotAction; public static bool holdingWeaponModifier; public static bool toggledWeaponSlot; public static PlayerControllerB localPlayerController => StartOfRound.Instance?.localPlayerController; public static ReservedPlayerData localPlayerData => PlayerPatcher.playerDataLocal; [HarmonyPatch(typeof(PreInitSceneScript), "Awake")] [HarmonyPrefix] public static void AddToKeybindMenu() { //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Expected O, but got Unknown //IL_0025: 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) Plugin.Log("Initializing hotkeys."); if (InputUtilsCompat.Enabled) { Asset = InputUtilsCompat.Asset; ActionMap = Asset.actionMaps[0]; ToggleWeaponSlotAction = InputUtilsCompat.ToggleWeaponHotkey; } else { Asset = ScriptableObject.CreateInstance<InputActionAsset>(); ActionMap = new InputActionMap("ReservedItemSlots"); InputActionSetupExtensions.AddActionMap(Asset, ActionMap); ToggleWeaponSlotAction = InputActionSetupExtensions.AddAction(ActionMap, "ReservedItemSlots.SwapToWeaponSlot", (InputActionType)0, ConfigSettings.swapToWeaponSlotHotkey.Value, (string)null, (string)null, (string)null, (string)null); } } [HarmonyPatch(typeof(StartOfRound), "OnEnable")] [HarmonyPostfix] public static void OnEnable() { Asset.Enable(); ToggleWeaponSlotAction.performed += OnSwapToWeaponSlot; ToggleWeaponSlotAction.canceled += OnSwapToWeaponSlot; } [HarmonyPatch(typeof(StartOfRound), "OnDisable")] [HarmonyPostfix] public static void OnDisable() { Asset.Disable(); ToggleWeaponSlotAction.performed -= OnSwapToWeaponSlot; ToggleWeaponSlotAction.canceled -= OnSwapToWeaponSlot; } private static void OnSwapToWeaponSlot(CallbackContext context) { if ((Object)(object)localPlayerController == (Object)null || localPlayerData == null || !localPlayerController.isPlayerControlled || (((NetworkBehaviour)localPlayerController).IsServer && !localPlayerController.isHostPlayerObject) || Patcher.reservedWeaponSlotIndex == -1) { return; } if (!ConfigSettings.swapToWeaponSlotToggled.Value) { holdingWeaponModifier = ((CallbackContext)(ref context)).performed; if (localPlayerData.currentItemSlot == Patcher.reservedWeaponSlotIndex) { } } else if (((CallbackContext)(ref context)).performed) { toggledWeaponSlot = !toggledWeaponSlot; if ((!toggledWeaponSlot || localPlayerData.currentItemSlot == Patcher.reservedWeaponSlotIndex) && !toggledWeaponSlot && localPlayerData.currentItemSlot != Patcher.reservedWeaponSlotIndex) { } } } } }
plugins/FlipMods-SkipToMultiplayerMenu/SkipToMultiplayerMenu.dll
Decompiled 10 months agousing System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using HarmonyLib; using UnityEngine.SceneManagement; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("SkipToMultiplayerMenu")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("SkipToMultiplayerMenu")] [assembly: AssemblyCopyright("Copyright © 2023")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("19daac4f-befb-4658-b237-679df1f71a19")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("1.0.0.0")] namespace SkipToMultiplayerMenu { [BepInPlugin("FlipMods.SkipToMultiplayerMenu", "SkipToMultiplayerMenu", "1.0.0")] public class Plugin : BaseUnityPlugin { private Harmony _harmony; private static Plugin instance; private void Awake() { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown instance = this; _harmony = new Harmony("SkipToMultiplayerMenu"); _harmony.PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"SkipToMultiplayerMenu loaded"); } public static void Log(string message) { ((BaseUnityPlugin)instance).Logger.LogInfo((object)message); } } public static class PluginInfo { public const string PLUGIN_GUID = "FlipMods.SkipToMultiplayerMenu"; public const string PLUGIN_NAME = "SkipToMultiplayerMenu"; public const string PLUGIN_VERSION = "1.0.0"; } } namespace SkipToMultiplayerMenu.Patches { [HarmonyPatch] internal class SkipToMultiplayerMenuPatcher { private static bool skippedPreInitScene; private static bool skippedInitScene; [HarmonyPatch(typeof(PreInitSceneScript), "Awake")] [HarmonyPrefix] public static bool InitializeGameManager() { if (skippedPreInitScene) { return true; } skippedPreInitScene = true; Plugin.Log("Loading GameManager in InitScene."); SceneManager.LoadScene("InitScene"); return false; } [HarmonyPatch(typeof(InitializeGame), "Start")] [HarmonyPrefix] public static bool LoadMultiplayerMenuScene() { if (skippedInitScene) { return true; } skippedInitScene = true; Plugin.Log("Skipping to MainMenu scene."); SceneManager.LoadScene("MainMenu"); return false; } } }