Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of SmallLobby v1.0.2
SmallLobby.dll
Decompiled 2 years agousing System; using 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.Logging; using GameNetcodeStuff; using HarmonyLib; 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("SmallLobby")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("SmallLobby")] [assembly: AssemblyCopyright("Copyright © 2023")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("48d2f6b1-c21c-43be-a1ba-3cdaba06d8ca")] [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 SmallLobby { public class Globals { public static int playerAmount = 4; } [BepInPlugin("ungodlyaura.SmallLobby", "Small Lobby", "1.0.2")] public class LobbyMod : BaseUnityPlugin { private const string modGUID = "ungodlyaura.SmallLobby"; private const string modName = "Small Lobby"; private const string modVersion = "1.0.2"; private readonly Harmony harmony = new Harmony("ungodlyaura.SmallLobby"); private static LobbyMod Instance; internal ManualLogSource mls; private void Awake() { if ((Object)(object)Instance == (Object)null) { Instance = this; } mls = Logger.CreateLogSource("ungodlyaura.SmallLobby"); harmony.PatchAll(); } } } namespace SmallLobby.Patches { public class TimeOfDayPatch { [HarmonyPatch(typeof(TimeOfDay), "Start")] [HarmonyPostfix] private static void TimeOfDayOnStartPost(TimeOfDay __instance) { __instance.globalTimeSpeedMultiplier = 1f - (float)(4 - Globals.playerAmount) * 0.1f; } } [HarmonyPatch(typeof(RoundManager), "DespawnPropsAtEndOfRound")] public class RoundManagerPatch { private static bool Prefix(RoundManager __instance) { GrabbableObject[] array = Object.FindObjectsOfType<GrabbableObject>(); for (int i = 0; i < array.Length; i++) { if ((!array[i].isHeld && !array[i].isInShipRoom) || (StartOfRound.Instance.allPlayersDead && Globals.playerAmount > 2 && array[i].itemProperties.isScrap)) { if (array[i].isHeld && (Object)(object)array[i].playerHeldBy != (Object)null) { array[i].playerHeldBy.DropAllHeldItems(true, false); } ((Component)array[i]).gameObject.GetComponent<NetworkObject>().Despawn(true); } else { array[i].scrapPersistedThroughRounds = true; } if (__instance.spawnedSyncedObjects.Contains(((Component)array[i]).gameObject)) { __instance.spawnedSyncedObjects.Remove(((Component)array[i]).gameObject); } } GameObject[] array2 = GameObject.FindGameObjectsWithTag("TemporaryEffect"); for (int j = 0; j < array2.Length; j++) { Object.Destroy((Object)(object)array2[j]); } return false; } } [HarmonyPatch(typeof(HUDManager), "Update")] [HarmonyPriority(100)] public class HUDManagerPatch { private static int playerAmountCheck = 4; private static bool Prefix(HUDManager __instance) { //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_015a: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_0203: Unknown result type (might be due to invalid IL or missing references) //IL_020d: Unknown result type (might be due to invalid IL or missing references) if (playerAmountCheck != Globals.playerAmount) { playerAmountCheck = Globals.playerAmount; if (Globals.playerAmount == 0) { Globals.playerAmount = 1; } int num = 8 - Globals.playerAmount; List<Image> list = new List<Image>(__instance.itemSlotIconFrames); List<Image> list2 = new List<Image>(__instance.itemSlotIcons); float num2 = Mathf.Abs(((Graphic)list[1]).rectTransform.anchoredPosition.x - ((Graphic)list[0]).rectTransform.anchoredPosition.x); float y = ((Component)list[0]).GetComponent<RectTransform>().anchoredPosition.y; Vector3 eulerAngles = ((Transform)((Graphic)list[0]).rectTransform).eulerAngles; Vector3 eulerAngles2 = ((Transform)((Graphic)list2[0]).rectTransform).eulerAngles; for (int i = 0; i < num; i++) { if (i >= list.Count) { list.Add(Object.Instantiate<Image>(list[i - 1], ((Component)list[0]).transform.parent)); list2.Add(((Component)((Component)list[i]).transform.GetChild(0)).GetComponent<Image>()); } ((Object)list[i]).name = $"Slot{i}"; ((Graphic)list[i]).rectTransform.anchoredPosition = Vector2.up * y; ((Transform)((Graphic)list[i]).rectTransform).eulerAngles = eulerAngles; ((Object)list2[i]).name = "Icon"; ((Transform)((Graphic)list2[i]).rectTransform).eulerAngles = eulerAngles2; } float num3 = num2 * (float)(list.Count - 1); float num4 = num3 / 2f; for (int j = 0; j < list.Count; j++) { float num5 = (float)j * num2 - num4; ((Graphic)list[j]).rectTransform.anchoredPosition = new Vector2(num5, ((Graphic)list[j]).rectTransform.anchoredPosition.y); } __instance.itemSlotIconFrames = list.ToArray(); __instance.itemSlotIcons = list2.ToArray(); } return true; } } [HarmonyPatch(typeof(StartOfRound), "Update")] [HarmonyPriority(100)] public class StartOfRoundPatch { private static bool Prefix(StartOfRound __instance) { __instance.maxShipItemCapacity = 1000; if (Globals.playerAmount != __instance.ClientPlayerList.Count) { Globals.playerAmount = __instance.ClientPlayerList.Count; } return true; } } [HarmonyPatch] internal static class HotbarSlotSync { private static PlayerControllerB localPlayerController; [HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")] [HarmonyPostfix] public static void Init(PlayerControllerB __instance) { //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("HotbarSlotChange", new HandleNamedMessageDelegate(OnReceiveHotbarSlotChange)); } } public static void SendHotbarSlotChange(int hotbarSlot) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_003f: 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); try { ((FastBufferWriter)(ref val)).WriteValue<int>(ref hotbarSlot, default(ForPrimitives)); NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("HotbarSlotChange", 0uL, val, (NetworkDelivery)3); } finally { ((IDisposable)(FastBufferWriter)(ref val)).Dispose(); } } } private static void OnReceiveHotbarSlotChange(ulong clientId, FastBufferReader reader) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) if (clientId != localPlayerController.playerClientId && ((FastBufferReader)(ref reader)).TryBeginRead(4)) { int hotbarSlot = default(int); ((FastBufferReader)(ref reader)).ReadValue<int>(ref hotbarSlot, default(ForPrimitives)); UpdateClientHotbarSlot(clientId, hotbarSlot); } } private static void UpdateClientHotbarSlot(ulong clientId, int hotbarSlot) { for (int i = 0; i < StartOfRound.Instance.allPlayerScripts.Length; i++) { if (StartOfRound.Instance.allPlayerScripts[i].playerClientId == clientId) { CallSwitchToItemSlotMethod(StartOfRound.Instance.allPlayerScripts[i], hotbarSlot); break; } } } public static void SwapHotbarSlot(int hotbarIndex) { SendHotbarSlotChange(hotbarIndex); CallSwitchToItemSlotMethod(localPlayerController, hotbarIndex); } private static void CallSwitchToItemSlotMethod(PlayerControllerB player, int hotbarIndex) { MethodInfo method = ((object)player).GetType().GetMethod("SwitchToItemSlot", BindingFlags.Instance | BindingFlags.NonPublic); method.Invoke(player, new object[2] { hotbarIndex, null }); } } [HarmonyPatch] internal class Keybinds { private static InputAction[] quickItemShortcutActions; private static PlayerControllerB localPlayerController; [HarmonyPatch(typeof(PlayerControllerB), "Awake")] [HarmonyPostfix] public static void Setup(PlayerControllerB __instance) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006f: 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_0087: 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_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Expected O, but got Unknown localPlayerController = __instance; MovementActions movement = localPlayerController.playerActions.Movement; BindingSyntax val = InputActionSetupExtensions.ChangeBinding(((MovementActions)(ref movement)).Emote1, 0); ((BindingSyntax)(ref val)).Erase(); movement = localPlayerController.playerActions.Movement; InputActionSetupExtensions.AddBinding(((MovementActions)(ref movement)).Emote1, "<Keyboard>/F1", (string)null, (string)null, (string)null); movement = localPlayerController.playerActions.Movement; val = InputActionSetupExtensions.ChangeBinding(((MovementActions)(ref movement)).Emote2, 0); ((BindingSyntax)(ref val)).Erase(); movement = localPlayerController.playerActions.Movement; InputActionSetupExtensions.AddBinding(((MovementActions)(ref movement)).Emote2, "<Keyboard>/F2", (string)null, (string)null, (string)null); quickItemShortcutActions = (InputAction[])(object)new InputAction[__instance.ItemSlots.Length + 8 - Globals.playerAmount]; for (int i = 0; i < quickItemShortcutActions.Length; i++) { quickItemShortcutActions[i] = new InputAction((string)null, (InputActionType)0, $"<Keyboard>/{i + 1}", "Press", (string)null, (string)null); } if (((Component)localPlayerController).gameObject.activeSelf) { for (int j = 0; j < quickItemShortcutActions.Length; j++) { quickItemShortcutActions[j].Enable(); quickItemShortcutActions[j].performed += OnPressItemSlotHotkeyAction; } } } private static void SubscribeToEvents() { for (int i = 0; i < quickItemShortcutActions.Length; i++) { quickItemShortcutActions[i].Enable(); quickItemShortcutActions[i].performed += OnPressItemSlotHotkeyAction; } } [HarmonyPatch(typeof(PlayerControllerB), "OnEnable")] [HarmonyPostfix] public static void OnEnable(PlayerControllerB __instance) { if ((Object)(object)__instance == (Object)(object)localPlayerController) { SubscribeToEvents(); } } [HarmonyPatch(typeof(PlayerControllerB), "OnDisable")] [HarmonyPostfix] public static void OnDisable(PlayerControllerB __instance) { for (int i = 0; i < quickItemShortcutActions.Length; i++) { quickItemShortcutActions[i].performed -= OnPressItemSlotHotkeyAction; quickItemShortcutActions[i].Disable(); } } private static void OnPressItemSlotHotkeyAction(CallbackContext context) { if (!((Object)(object)localPlayerController == (Object)null) && ((NetworkBehaviour)localPlayerController).IsOwner && localPlayerController.isPlayerControlled && !localPlayerController.inTerminalMenu && (!((NetworkBehaviour)localPlayerController).IsServer || localPlayerController.isHostPlayerObject) && ((CallbackContext)(ref context)).performed) { string name = ((CallbackContext)(ref context)).control.name; if (int.TryParse(name, out var result)) { result--; HotbarSlotSync.SwapHotbarSlot(result); } } } } [HarmonyPatch(typeof(PlayerControllerB), "Update")] internal class PlayerControllerBPatch { [HarmonyPatch(typeof(PlayerControllerB), "SwitchItem_performed")] [HarmonyTranspiler] private static IEnumerable<CodeInstruction> PatchSwitchItemInterval(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.3f) { list[i].operand = 0.01f; break; } } return list.AsEnumerable(); } [HarmonyPatch("Update")] [HarmonyPostfix] private static void ItemsPatch(ref float ___carryWeight, ref bool ___twoHanded, PlayerControllerB __instance) { if (__instance.ItemSlots.Length != 8 - Globals.playerAmount) { __instance.DropAllHeldItems(true, false); __instance.ItemSlots = (GrabbableObject[])(object)new GrabbableObject[8 - Globals.playerAmount]; } float num = 1f; if (__instance.ItemSlots != null) { GrabbableObject[] itemSlots = __instance.ItemSlots; foreach (GrabbableObject val in itemSlots) { if ((Object)(object)val != (Object)null) { num += Mathf.Clamp(val.itemProperties.weight - 1f, 0f, 10f); } } } num -= 1f; num *= 1f * (0.25f * (float)Globals.playerAmount); if (Globals.playerAmount < 4) { ___twoHanded = false; } num += 1f; ___carryWeight = num; } } }