コード例 #1
0
        public static void ClearRandomQuickSlot()
        {
            QuickSlots quickSlots = Inventory.main.quickSlots;

            // Find all slots which have items in them
            List <int> activeSlots = new List <int>();

            for (int i = 0; i < quickSlots.slotCount; i++)
            {
                if (quickSlots.GetSlotItem(i) != null)
                {
                    activeSlots.Add(i);
                }
            }

            if (activeSlots.Count == 0)
            {
                // Prevent OutOfBounds errors
                return;
            }

            System.Random random       = new System.Random();
            int           randomSlotID = activeSlots[random.Next(0, activeSlots.Count)];

            quickSlots.Unbind(randomSlotID);
        }
コード例 #2
0
        public static bool Prefix(QuickSlots __instance)
        {
            if ((__instance._heldItem == null) || !DeathRun.config.firstAidQuickSlot)
            {
                return(true);
            }

            Pickupable item = __instance._heldItem.item;

            if (item.GetTechType() != TechType.FirstAidKit)
            {
                return(true);
            }

            Survival component = Player.main.GetComponent <Survival>();

            if (component != null)
            {
                if (component.Use(item.gameObject))
                {
                    __instance.refillTechType = item.GetTechType();
                    __instance.refillSlot     = __instance.GetSlotByItem(__instance._heldItem);
                    __instance.desiredSlot    = __instance.refillSlot;

                    UnityEngine.Object.Destroy(item.gameObject);
                    return(false);
                }
            }

            return(false);
        }
        private static bool Prefix(QuickSlots __instance, InventoryItem item, ref int __result)
        {
            //check if there is a empty slot
            int firstEmpty = __instance.GetFirstEmpty();

            if (firstEmpty == -1)
            {
                __result = -1;
            }
            else
            {
                //Checklogic
                //1. Check if Mod is active
                //2. true if user use the custom list AND the item is found
                //check using before checking item because && will increase performance when mod is not in use
                //- 1 OR 2 musst be true
                if ((ICM.Config_ModEnable == false) | (ICM.Config_AllowCustomList && PlayerAllowBind(item)))
                {
                    __instance.Bind(firstEmpty, item);
                    __result = firstEmpty;
                }
                else
                {
                    //As i cannot stop the execute on a patch methode give back a result seperatly to skip the Slot Select on the calling function
                    __result = -1;
                }
            }
            return(false);
        }
コード例 #4
0
        private static void Prefix(QuickSlots __instance)
        {
            if (!Input.GetKeyDown(KeyCode.I) || uGUI_PDA.main.tabOpen != PDATab.None || DevConsole.instance.state || timeCheck != 0)
            {
                return;
            }
            var item     = __instance.heldItem;
            var techType = item?.item?.GetTechType() ?? TechType.None;
            var tool     = item?.item?.gameObject.GetComponent <PlayerTool>();

            if (GameOptions.GetVrAnimationMode() || tool == null || !tool.hasFirstUseAnimation)
            {
                return;
            }
            if (Player.main.usedTools.Contains(techType))
            {
                Player.main.usedTools.Remove(techType);
            }

            var slot = __instance.GetSlotByItem(item);

            if (slot == -1)
            {
                return;
            }
            __instance.SelectImmediate(slot);
            timeCheck = Time.time + tool.holsterTime;
            CoroutineHost.StartCoroutine(SelectDelay(__instance, slot));
        }
        static void Postfix(Inventory __instance)
        {
            var slotCount     = Mod.config.SlotCount;
            var player        = __instance.GetComponent <Player>();
            var newQuickSlots = new QuickSlots(__instance.gameObject, __instance.toolSocket, __instance.cameraSocket, __instance, player.rightHandSlot, slotCount);
            var setQuickSlots = __instance.GetType().GetMethod("set_quickSlots", BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);

            setQuickSlots.Invoke(__instance, new object[] { newQuickSlots });
        }
コード例 #6
0
        public static void Prefix(QuickSlots __instance, int slotID, ref NitroxTechType __state)
        {
            InventoryItem item = ((InventoryItem[])bindingField.GetValue(__instance))[slotID];

            if (item == null)
            {
                return;
            }
            __state = Player.main.IsToolUsed(item.item.GetTechType()) ? item.item.GetTechType().ToDto() : null;
        }
コード例 #7
0
        private static IEnumerator SelectDelay(QuickSlots quickSlots, int slot)
        {
            while (Time.time < timeCheck)
            {
                yield return(new WaitForSeconds(0.01f));
            }

            quickSlots.Select(slot);
            timeCheck = 0;
        }
コード例 #8
0
        static bool QuickSlots_SetAnimationState_Prefix(QuickSlots __instance, string toolName)
        {
            if (toolName != trfBuilderToolName)
            {
                return(true);
            }

            __instance.SetAnimationState("terraformer");
            return(false);
        }
コード例 #9
0
        static bool patchAnimation(QuickSlots __instance, string toolName)
        {
            if (toolName != gravtrap)
            {
                return(true);
            }

            __instance.SetAnimationState("gravsphere");
            return(false);
        }
コード例 #10
0
        public static void Postfix(QuickSlots __instance)
        {
            // TODO: The binding should only be send on a timer and/or on disconnect. But this functionality/framework is not implemented yet.
            string[] binding = __instance.SaveBinding();

            for (int i = 0; i < binding.Length; i++)
            {
                binding[i] ??= "null"; // ProtoBuf can't handle null objects in Lists
            }

            player.BroadcastQuickSlotsBindingChanged(binding.ToList());
        }
コード例 #11
0
        internal static void Prefix(QuickSlots __instance, GameObject owner, Transform toolSocket, Transform cameraSocket, Inventory inv, Transform slotTr, ref int slotCount)
        {
            if (isPatched)
            {
                return;
            }

            __instance.GetType().GetField("slotNames", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.GetField | BindingFlags.SetField).SetValue(__instance, QuickSlotHelper.ExpandedQuickSlotNames);

            slotCount = Config.MAXSLOTS;

            isPatched = true;
        }
コード例 #12
0
        internal static void Prefix(QuickSlots __instance, GameObject owner, Transform toolSocket, Transform cameraSocket, Inventory inv, Transform slotTr, ref int slotCount)
        {
            if (Main.isPatched)
            {
                return;
            }

            __instance.SetPrivateField("slotNames", ExpandedQuickSlotNames, BindingFlags.Static);

            slotCount = QSEConfig.MAXSLOTS;

            SNLogger.Log("QuickSlots constructor Patched.");

            Main.isPatched = true;
        }
コード例 #13
0
        internal static void Prefix(QuickSlots __instance, GameObject owner, Transform toolSocket, Transform cameraSocket, Inventory inv, Transform slotTr, ref int slotCount)
        {
            if (isPatched)
            {
                return;
            }

            __instance.GetType().GetField("slotNames", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.GetField | BindingFlags.SetField).SetValue(__instance, ExpandedQuickSlotNames);

            slotCount = QSEConfig.MAXSLOTS;

            isPatched = true;

            SNLogger.Log($"[{QSEConfig.PROGRAM_NAME}] QuickSlots Constructor patched!");
        }
コード例 #14
0
        static void Postfix(Inventory __instance)
        {
            int slotCount = Mod.config.SlotCount;

            string[] newSlotNames = new string[slotCount];
            for (int i = 0; i < slotCount; ++i)
            {
                newSlotNames[i] = "QuickSlot" + i;
            }
            typeof(QuickSlots).GetField("slotNames", BindingFlags.Static | BindingFlags.NonPublic).SetValue(null, newSlotNames);

            Player     player        = __instance.GetComponent <Player>();
            QuickSlots newQuickSlots = new QuickSlots(__instance.gameObject, __instance.toolSocket, __instance.cameraSocket, __instance, player.rightHandSlot, slotCount);

            var setQuickSlots = __instance.GetType().GetMethod("set_quickSlots", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);

            setQuickSlots.Invoke(__instance, new object[] { newQuickSlots });

            Logger.Log("Inventory Quick Modified, new slot count: {0}", __instance.quickSlots.slotCount);
        }
        private static bool Prefix(QuickSlots __instance, InventoryItem item, ref int __result)
        {
            //ICM.Load();

            int num = -1;

            for (int i = 0; i < __instance.binding.Length; i++)
            {
                if (__instance.binding[i] == null)
                {
                    num = i;
                    break;
                }
            }
            if (num == -1)
            {
                __result = -1;
            }

            /*
             * //Check if intro is running
             * if(IntroVignette.isIntroActive == true)
             * {
             *  Logger.Log(Logger.Level.Warn, "Intro true");
             * }
             * else
             * {
             *  Logger.Log(Logger.Level.Warn, "Intro false");
             * }
             */

            if ((ICM.Config_ModEnable == false) | (IntroVignette.isIntroActive == true) | (ICM.Config_AllowCustomList && PlayerAllowBind(item)))
            //If the mod is disabled or the intro is runing run the original Code. After all check if the User allow adding to improve performance check if Allow is enabled before checking the item.
            {
                __instance.Bind(num, item);
            }
            __result = num;

            return(false);
        }
コード例 #16
0
        static void Prefix(QuickSlots __instance)
        {
            if (Input.GetKeyDown(KeyCode.I) && timeCheck == 0)
            {
                InventoryItem item     = __instance.heldItem;
                TechType      techType = item?.item?.GetTechType() ?? TechType.None;
                PlayerTool    tool     = item?.item?.gameObject?.GetComponent <PlayerTool>();
                if (!GameOptions.GetVrAnimationMode() && tool != null && tool.hasFirstUseAnimation)
                {
                    if (Player.main.usedTools.Contains(techType))
                    {
                        Player.main.usedTools.Remove(techType);
                    }

                    int slot = __instance.GetSlotByItem(item);
                    if (slot != -1)
                    {
                        __instance.SelectImmediate(slot);
                        timeCheck = Time.time + tool.holsterTime;
                        CoroutineHost.StartCoroutine(SelectDelay(__instance, slot));
                    }
                }
            }
        }
コード例 #17
0
        public static void RandomizeQuickSlots()
        {
            QuickSlots quickSlots = Inventory.main.quickSlots;

            // Make a list of all slots (including empty slots)
            List <InventoryItem> allSlots = new List <InventoryItem>();

            for (int i = 0; i < quickSlots.slotCount; i++)
            {
                allSlots.Add(quickSlots.GetSlotItem(i));
            }

            // Shuffle the list
            System.Random random = new System.Random();
            int           n      = allSlots.Count;

            while (n > 1)
            {
                n--;
                int           k     = random.Next(n + 1);
                InventoryItem value = allSlots[k];
                allSlots[k] = allSlots[n];
                allSlots[n] = value;
            }

            // Set the quick slots
            for (int i = 0; i < quickSlots.slotCount; i++)
            {
                quickSlots.binding[i] = allSlots[i];
            }
            // Notify the game that the slots have changed
            for (int i = 0; i < quickSlots.slotCount; i++)
            {
                quickSlots.NotifyBind(i, allSlots[i] != null);
            }
        }
コード例 #18
0
    /// <summary>
    /// Save Game
    /// </summary>
    public static void Save(GameObject plants, GameObject chests, Inventory inventory, QuickSlots quickSlots)
    {
        BinaryFormatter bf   = new BinaryFormatter();
        FileStream      file = File.Create(saveGamePath);

        savegameData = new SavegameData();

        // Save Plants
        foreach (Plant plant in plants.GetComponentsInChildren <Plant>())
        {
            savegameData.plants.Add(plant.data);
        }

        // Save Inventory
        savegameData.inventorySize = inventory.availableSize;
        for (int i = 0; i < inventory.availableSize; i++)
        {
            savegameData.inventoryItems[i] = inventory.uiItems[i].ToData();
        }

        // Save QuickSlots and References to inventory
        for (int i = 0; i < QuickSlots.SIZE; i++)
        {
            savegameData.inventoryQuickSlotRef[i] = quickSlots.inventoryReference[i];
        }

        // Save Chests
        foreach (Chest chest in chests.GetComponentsInChildren <Chest>())
        {
            savegameData.chests.Add(chest.data);
        }

        bf.Serialize(file, savegameData);
        file.Close();

        Debug.Log("File Saved");
    }