Exemple #1
0
        /*
         * update settings and item, drone, ship and warper count
         * first determine if the local player has the station window opened and hadle that accordingly.
         */
        private static void UpdateSettingsUI(StationUI packet)
        {
            UIStationWindow stationWindow = UIRoot.instance.uiGame.stationWindow;

            if (stationWindow != null)
            {
                int        _stationId = (int)AccessTools.Field(typeof(UIStationWindow), "_stationId")?.GetValue(stationWindow);
                PlanetData pData      = GameMain.galaxy.PlanetById(packet.planetId);
                if (pData?.factory == null || pData?.factory?.transport == null)
                {
                    if (GameMain.data.galacticTransport.stationPool.Length > packet.stationGId && GameMain.data.galacticTransport.stationPool[packet.stationGId] != null)
                    {
                        // client never was on this planet before or has it unloaded, but has a fake structure created, so update it
                        UpdateSettingsUIBackground(packet, pData, packet.stationGId);
                    }
                    return;
                }
                for (int i = 0; i < pData.factory.transport.stationPool.Length; i++)
                {
                    if (pData.factory.transport.stationPool[i] != null)
                    {
                        int id = ((packet.isStellar == true) ? pData.factory.transport.stationPool[i].gid : pData.factory.transport.stationPool[i].id);
                        if (id == packet.stationGId)
                        {
                            if (pData.factory.transport.stationPool[i].id != _stationId)
                            {
                                // receiving side has the UI closed or another stations UI opened. still update drones, ships, warpers and power consumption for clients and update all for host
                                UpdateSettingsUIBackground(packet, pData, pData.factory.transport.stationPool[i].gid);
                                return;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }

                // this locks the patches so we can call vanilla functions without triggering our patches to avoid endless loops
                using (ILSShipManager.PatchLockILS.On())
                {
                    if (packet.settingIndex == StationUI.UIsettings.MaxChargePower)
                    {
                        stationWindow.OnMaxChargePowerSliderValueChange(packet.settingValue);
                    }
                    if (packet.settingIndex == StationUI.UIsettings.MaxTripDrones)
                    {
                        stationWindow.OnMaxTripDroneSliderValueChange(packet.settingValue);
                    }
                    if (packet.settingIndex == StationUI.UIsettings.MaxTripVessel)
                    {
                        stationWindow.OnMaxTripVesselSliderValueChange(packet.settingValue);
                    }
                    if (packet.settingIndex == StationUI.UIsettings.MinDeliverDrone)
                    {
                        stationWindow.OnMinDeliverDroneValueChange(packet.settingValue);
                    }
                    if (packet.settingIndex == StationUI.UIsettings.MinDeliverVessel)
                    {
                        stationWindow.OnMinDeliverVesselValueChange(packet.settingValue);
                    }
                    if (packet.settingIndex == StationUI.UIsettings.WarpDistance)
                    {
                        stationWindow.OnWarperDistanceValueChange(packet.settingValue);
                    }
                    if (packet.settingIndex == StationUI.UIsettings.warperNeeded)
                    {
                        stationWindow.OnWarperNecessaryClick(0);
                    }
                    if (packet.settingIndex == StationUI.UIsettings.includeCollectors)
                    {
                        Type[]   args   = new Type[1];
                        object[] values = new object[1];
                        args[0]   = typeof(int);
                        values[0] = 0;
                        AccessTools.Method(typeof(UIStationWindow), "OnIncludeOrbitCollectorClick", args).Invoke(stationWindow, values);
                    }
                    if (packet.settingIndex >= StationUI.UIsettings.setDroneCount && packet.settingIndex <= StationUI.UIsettings.setWarperCount)
                    {
                        StationComponent[] stationPool = pData.factory.transport.stationPool;
                        if (packet.settingIndex == StationUI.UIsettings.setDroneCount)
                        {
                            Type[]   args   = new Type[1];
                            object[] values = new object[1];
                            args[0]   = typeof(int);
                            values[0] = 0;
                            if (UIRequestedShipDronWarpChange)
                            {
                                AccessTools.Method(typeof(UIStationWindow), "OnDroneIconClick", args).Invoke(stationWindow, values);
                                UIRequestedShipDronWarpChange = false;
                            }
                            stationPool[_stationId].idleDroneCount = (int)packet.settingValue;
                        }
                        if (packet.settingIndex == StationUI.UIsettings.setShipCount)
                        {
                            Type[]   args   = new Type[1];
                            object[] values = new object[1];
                            args[0]   = typeof(int);
                            values[0] = 0;
                            if (UIRequestedShipDronWarpChange)
                            {
                                AccessTools.Method(typeof(UIStationWindow), "OnShipIconClick", args).Invoke(stationWindow, values);
                                UIRequestedShipDronWarpChange = false;
                            }
                            stationPool[_stationId].idleShipCount = (int)packet.settingValue;
                        }
                        if (packet.settingIndex == StationUI.UIsettings.setWarperCount)
                        {
                            Type[]   args   = new Type[1];
                            object[] values = new object[1];
                            args[0]   = typeof(int);
                            values[0] = 0;
                            if (UIRequestedShipDronWarpChange)
                            {
                                AccessTools.Method(typeof(UIStationWindow), "OnWarperIconClick", args).Invoke(stationWindow, values);
                                UIRequestedShipDronWarpChange = false;
                            }
                            stationPool[_stationId].warperCount = (int)packet.settingValue;
                        }
                    }

                    /*
                     * the idea is that clients request that they want to apply a change and do so once the server responded with an okay.
                     * the calls to OnItemIconMouseDown() and OnItemIconMouseUp() are blocked for clients and called only from here.
                     */
                    if (packet.settingIndex == StationUI.UIsettings.addOrRemoveItemFromStorageReq)
                    {
                        StationComponent[] stationPool = pData.factory.transport.stationPool;
                        if (stationPool[_stationId].storage != null)
                        {
                            if (packet.shouldMimick)
                            {
                                BaseEventData      mouseEvent = lastMouseEvent;
                                UIStationStorage[] storageUIs = (UIStationStorage[])AccessTools.Field(typeof(UIStationWindow), "storageUIs").GetValue(stationWindow);

                                if (lastMouseEvent != null)
                                {
                                    // TODO: change this such that only server sends the response, else clients with a desynced state could change servers storage to a faulty value
                                    // issue #249
                                    if (lastMouseEventWasDown)
                                    {
                                        storageUIs[packet.storageIdx].OnItemIconMouseDown(mouseEvent);
                                        StationUI packet2 = new StationUI(packet.stationGId, packet.planetId, packet.storageIdx, StationUI.UIsettings.addOrRemoveItemFromStorageResp, packet.itemId, stationPool[_stationId].storage[packet.storageIdx].count, packet.isStellar);
                                        LocalPlayer.SendPacket(packet2);
                                    }
                                    else
                                    {
                                        storageUIs[packet.storageIdx].OnItemIconMouseUp(mouseEvent);
                                        StationUI packet2 = new StationUI(packet.stationGId, packet.planetId, packet.storageIdx, StationUI.UIsettings.addOrRemoveItemFromStorageResp, packet.itemId, stationPool[_stationId].storage[packet.storageIdx].count, packet.isStellar);
                                        LocalPlayer.SendPacket(packet2);
                                    }
                                    lastMouseEvent = null;
                                }
                            }
                        }
                    }
                    if (packet.settingIndex == StationUI.UIsettings.addOrRemoveItemFromStorageResp)
                    {
                        StationComponent[] stationPool = pData.factory.transport.stationPool;
                        if (stationPool[_stationId].storage != null)
                        {
                            stationPool[_stationId].storage[packet.storageIdx].count = (int)packet.settingValue;
                        }
                    }
                }
            }
        }
Exemple #2
0
        /*
         * Update station settings and drone, ship and warper counts.
         *
         * First determine if the local player has the station window opened and handle that accordingly.
         */
        private static void UpdateSettingsUI(StationUI packet)
        {
            UIStationWindow stationWindow = UIRoot.instance.uiGame.stationWindow;

            StationComponent stationComponent = null;
            PlanetData       planet           = GameMain.galaxy?.PlanetById(packet.PlanetId);

            // If we can't find planet or the factory for said planet, we can just skip this
            if (planet?.factory?.transport == null)
            {
                return;
            }

            StationComponent[] gStationPool = GameMain.data.galacticTransport.stationPool;
            StationComponent[] stationPool  = planet?.factory?.transport?.stationPool;

            // Figure out if we're dealing with a PLS or a ILS station
            stationComponent = packet.StationGId > 0 ? gStationPool[packet.StationGId] : stationPool?[packet.StationId];

            if (stationComponent == null)
            {
                Log.Error($"UpdateStorageUI: Unable to find requested station on planet {packet.PlanetId} with id {packet.StationId} and gid of {packet.StationGId}");
                return;
            }

            if (stationWindow == null)
            {
                return;
            }

            int _stationId = (int)AccessTools.Field(typeof(UIStationWindow), "_stationId")?.GetValue(stationWindow);

            // Client has no knowledge of the planet, closed the window or
            // opened a different station, do all updates in the background.
            if (planet?.factory?.transport == null || stationComponent.id != _stationId)
            {
                UpdateSettingsUIBackground(packet, planet, stationComponent);
                return;
            }

            // this locks the patches so we can call vanilla functions without triggering our patches to avoid endless loops
            using (ILSShipManager.PatchLockILS.On())
            {
                if (packet.SettingIndex == StationUI.EUISettings.MaxChargePower)
                {
                    stationWindow.OnMaxChargePowerSliderValueChange(packet.SettingValue);
                }
                if (packet.SettingIndex == StationUI.EUISettings.MaxTripDrones)
                {
                    stationWindow.OnMaxTripDroneSliderValueChange(packet.SettingValue);
                }
                if (packet.SettingIndex == StationUI.EUISettings.MaxTripVessel)
                {
                    stationWindow.OnMaxTripVesselSliderValueChange(packet.SettingValue);
                }
                if (packet.SettingIndex == StationUI.EUISettings.MinDeliverDrone)
                {
                    stationWindow.OnMinDeliverDroneValueChange(packet.SettingValue);
                }
                if (packet.SettingIndex == StationUI.EUISettings.MinDeliverVessel)
                {
                    stationWindow.OnMinDeliverVesselValueChange(packet.SettingValue);
                }
                if (packet.SettingIndex == StationUI.EUISettings.WarpDistance)
                {
                    stationWindow.OnWarperDistanceValueChange(packet.SettingValue);
                }
                if (packet.SettingIndex == StationUI.EUISettings.WarperNeeded)
                {
                    stationWindow.OnWarperNecessaryClick(0);
                }
                if (packet.SettingIndex == StationUI.EUISettings.IncludeCollectors)
                {
                    Type[]   args   = new Type[1];
                    object[] values = new object[1];
                    args[0]   = typeof(int);
                    values[0] = 0;
                    AccessTools.Method(typeof(UIStationWindow), "OnIncludeOrbitCollectorClick", args).Invoke(stationWindow, values);
                }
                if (packet.SettingIndex >= StationUI.EUISettings.SetDroneCount && packet.SettingIndex <= StationUI.EUISettings.SetWarperCount)
                {
                    if (packet.SettingIndex == StationUI.EUISettings.SetDroneCount)
                    {
                        Type[]   args   = new Type[1];
                        object[] values = new object[1];
                        args[0]   = typeof(int);
                        values[0] = 0;
                        if (UIRequestedShipDronWarpChange)
                        {
                            AccessTools.Method(typeof(UIStationWindow), "OnDroneIconClick", args).Invoke(stationWindow, values);
                            UIRequestedShipDronWarpChange = false;
                        }
                        stationComponent.idleDroneCount = (int)packet.SettingValue;
                    }
                    if (packet.SettingIndex == StationUI.EUISettings.SetShipCount)
                    {
                        Type[]   args   = new Type[1];
                        object[] values = new object[1];
                        args[0]   = typeof(int);
                        values[0] = 0;
                        if (UIRequestedShipDronWarpChange)
                        {
                            AccessTools.Method(typeof(UIStationWindow), "OnShipIconClick", args).Invoke(stationWindow, values);
                            UIRequestedShipDronWarpChange = false;
                        }
                        stationComponent.idleShipCount = (int)packet.SettingValue;
                    }
                    if (packet.SettingIndex == StationUI.EUISettings.SetWarperCount)
                    {
                        Type[]   args   = new Type[1];
                        object[] values = new object[1];
                        args[0]   = typeof(int);
                        values[0] = 0;
                        if (UIRequestedShipDronWarpChange)
                        {
                            AccessTools.Method(typeof(UIStationWindow), "OnWarperIconClick", args).Invoke(stationWindow, values);
                            UIRequestedShipDronWarpChange = false;
                        }
                        stationComponent.warperCount = (int)packet.SettingValue;
                    }
                }

                /*
                 * the idea is that clients request that they want to apply a change and do so once the server responded with an okay.
                 * the calls to OnItemIconMouseDown() and OnItemIconMouseUp() are blocked for clients and called only from here.
                 */
                if (packet.SettingIndex == StationUI.EUISettings.AddOrRemoveItemFromStorageRequest)
                {
                    if (stationComponent.storage != null)
                    {
                        if (packet.ShouldMimic)
                        {
                            BaseEventData      mouseEvent = LastMouseEvent;
                            UIStationStorage[] storageUIs = (UIStationStorage[])AccessTools.Field(typeof(UIStationWindow), "storageUIs").GetValue(stationWindow);

                            if (LastMouseEvent != null)
                            {
                                // TODO: change this such that only server sends the response, else clients with a desynced state could change servers storage to a faulty value
                                // issue #249
                                if (LastMouseEventWasDown)
                                {
                                    storageUIs[packet.StorageIdx].OnItemIconMouseDown(mouseEvent);
                                    StationUI packet2 = new StationUI(packet.PlanetId, packet.StationId, packet.StationGId, packet.StorageIdx, StationUI.EUISettings.AddOrRemoveItemFromStorageResponse, packet.ItemId, stationComponent.storage[packet.StorageIdx].count);
                                    LocalPlayer.SendPacket(packet2);
                                }
                                else
                                {
                                    storageUIs[packet.StorageIdx].OnItemIconMouseUp(mouseEvent);
                                    StationUI packet2 = new StationUI(packet.PlanetId, packet.StationId, packet.StationGId, packet.StorageIdx, StationUI.EUISettings.AddOrRemoveItemFromStorageResponse, packet.ItemId, stationComponent.storage[packet.StorageIdx].count);
                                    LocalPlayer.SendPacket(packet2);
                                }
                                LastMouseEvent = null;
                            }
                        }
                    }
                }
                if (packet.SettingIndex == StationUI.EUISettings.AddOrRemoveItemFromStorageResponse)
                {
                    if (stationComponent.storage != null)
                    {
                        stationComponent.storage[packet.StorageIdx].count = (int)packet.SettingValue;
                    }
                }
            }
        }
Exemple #3
0
        private static void UpdateSettingsUI(StationUI packet)
        {
            UIStationWindow stationWindow = UIRoot.instance.uiGame.stationWindow;

            if (stationWindow != null)
            {
                int        _stationId = (int)AccessTools.Field(typeof(UIStationWindow), "_stationId")?.GetValue(stationWindow);
                PlanetData pData      = GameMain.galaxy.PlanetById(packet.planetId);
                if (pData?.factory == null || pData?.factory?.transport == null)
                {
                    if (GameMain.data.galacticTransport.stationPool.Length > packet.stationGId && GameMain.data.galacticTransport.stationPool[packet.stationGId] != null)
                    {
                        // client never was on this planet before or has it unloaded, but has a fake structure created, so update it
                        UpdateSettingsUIBackground(packet, pData, packet.stationGId);
                    }
                    return;
                }
                for (int i = 0; i < pData.factory.transport.stationPool.Length; i++)
                {
                    if (pData.factory.transport.stationPool[i] != null && pData.factory.transport.stationPool[i].gid == packet.stationGId)
                    {
                        if (pData.factory.transport.stationPool[i].id != _stationId)
                        {
                            // receiving side has the UI closed or another stations UI opened. still update drones, ships, warpers and power consumption for clients and update all for host
                            UpdateSettingsUIBackground(packet, pData, pData.factory.transport.stationPool[i].gid);
                            return;
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                LocalPlayer.PatchLocks["UIStationWindow"]  = true;
                LocalPlayer.PatchLocks["UIStationStorage"] = true;
                if (packet.settingIndex == 0)
                {
                    stationWindow.OnMaxChargePowerSliderValueChange(packet.settingValue);
                }
                if (packet.settingIndex == 1)
                {
                    stationWindow.OnMaxTripDroneSliderValueChange(packet.settingValue);
                }
                if (packet.settingIndex == 2)
                {
                    stationWindow.OnMaxTripVesselSliderValueChange(packet.settingValue);
                }
                if (packet.settingIndex == 3)
                {
                    stationWindow.OnMinDeliverDroneValueChange(packet.settingValue);
                }
                if (packet.settingIndex == 4)
                {
                    stationWindow.OnMinDeliverVesselValueChange(packet.settingValue);
                }
                if (packet.settingIndex == 5)
                {
                    stationWindow.OnWarperDistanceValueChange(packet.settingValue);
                }
                if (packet.settingIndex == 6)
                {
                    stationWindow.OnWarperNecessaryClick(0);
                }
                if (packet.settingIndex == 7)
                {
                    Type[]   args   = new Type[1];
                    object[] values = new object[1];
                    args[0]   = typeof(int);
                    values[0] = 0;
                    AccessTools.Method(typeof(UIStationWindow), "OnIncludeOrbitCollectorClick", args).Invoke(stationWindow, values);
                }
                if (packet.settingIndex >= 8 && packet.settingIndex <= 10)
                {
                    StationComponent[] stationPool = pData.factory.transport.stationPool;
                    if (packet.settingIndex == 8)
                    {
                        Type[]   args   = new Type[1];
                        object[] values = new object[1];
                        args[0]   = typeof(int);
                        values[0] = 0;
                        if (UIRequestedShipDronWarpChange)
                        {
                            AccessTools.Method(typeof(UIStationWindow), "OnDroneIconClick", args).Invoke(stationWindow, values);
                            UIRequestedShipDronWarpChange = false;
                        }
                        stationPool[_stationId].idleDroneCount = (int)packet.settingValue;
                    }
                    if (packet.settingIndex == 9)
                    {
                        Type[]   args   = new Type[1];
                        object[] values = new object[1];
                        args[0]   = typeof(int);
                        values[0] = 0;
                        if (UIRequestedShipDronWarpChange)
                        {
                            AccessTools.Method(typeof(UIStationWindow), "OnShipIconClick", args).Invoke(stationWindow, values);
                            UIRequestedShipDronWarpChange = false;
                        }
                        stationPool[_stationId].idleShipCount = (int)packet.settingValue;
                    }
                    if (packet.settingIndex == 10)
                    {
                        Type[]   args   = new Type[1];
                        object[] values = new object[1];
                        args[0]   = typeof(int);
                        values[0] = 0;
                        if (UIRequestedShipDronWarpChange)
                        {
                            AccessTools.Method(typeof(UIStationWindow), "OnWarperIconClick", args).Invoke(stationWindow, values);
                            UIRequestedShipDronWarpChange = false;
                        }
                        stationPool[_stationId].warperCount = (int)packet.settingValue;
                    }
                }
                if (packet.settingIndex == 11)
                {
                    StationComponent[] stationPool = pData.factory.transport.stationPool;
                    if (stationPool[_stationId].storage != null)
                    {
                        if (packet.shouldMimick)
                        {
                            BaseEventData      mouseEvent = lastMouseEvent;
                            PointerEventData   pointEvent = mouseEvent as PointerEventData;
                            UIStationStorage[] storageUIs = (UIStationStorage[])AccessTools.Field(typeof(UIStationWindow), "storageUIs").GetValue(stationWindow);

                            if (lastMouseEvent != null)
                            {
                                if (lastMouseEventWasDown)
                                {
                                    storageUIs[packet.storageIdx].OnItemIconMouseDown(mouseEvent);
                                    StationUI packet2 = new StationUI(packet.stationGId, packet.planetId, packet.storageIdx, 12, packet.itemId, stationPool[_stationId].storage[packet.storageIdx].count);
                                    LocalPlayer.SendPacket(packet2);
                                }
                                else
                                {
                                    storageUIs[packet.storageIdx].OnItemIconMouseUp(mouseEvent);
                                    StationUI packet2 = new StationUI(packet.stationGId, packet.planetId, packet.storageIdx, 12, packet.itemId, stationPool[_stationId].storage[packet.storageIdx].count);
                                    LocalPlayer.SendPacket(packet2);
                                }
                                lastMouseEvent = null;
                            }
                        }
                        else
                        {
                            //stationPool[_stationId].storage[packet.storageIdx].count = (int)packet.settingValue;
                        }
                    }
                }
                if (packet.settingIndex == 12)
                {
                    Debug.Log("should set it");
                    StationComponent[] stationPool = pData.factory.transport.stationPool;
                    if (stationPool[_stationId].storage != null)
                    {
                        stationPool[_stationId].storage[packet.storageIdx].count = (int)packet.settingValue;
                    }
                }
                LocalPlayer.PatchLocks["UIStationWindow"]  = false;
                LocalPlayer.PatchLocks["UIStationStorage"] = false;
            }
        }