Ejemplo n.º 1
0
        public static bool EnterGame_Prefix(UIGalaxySelect __instance)
        {
            if (Multiplayer.IsInMultiplayerMenu)
            {
                Multiplayer.Session.IsInLobby = false;

                if (UIVirtualStarmap_Transpiler.customBirthPlanet != -1)
                {
                    Log.Debug((GameMain.data.galaxy.PlanetById(UIVirtualStarmap_Transpiler.customBirthPlanet) == null) ? "null" : "not null");
                    GameMain.data.galaxy.PlanetById(UIVirtualStarmap_Transpiler.customBirthPlanet)?.UnloadFactory();
                }

                if (((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost)
                {
                    UIRoot.instance.uiGame.planetDetail.gameObject.SetActive(false);

                    GameDesc gameDesc = __instance.gameDesc;
                    DSPGame.StartGameSkipPrologue(gameDesc);
                }
                else
                {
                    Multiplayer.Session.Network.SendPacket(new StartGameMessage());
                }
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        public static void _OnClose_Prefix(UIGalaxySelect __instance)
        {
            if (Multiplayer.IsInMultiplayerMenu && Multiplayer.Session.IsInLobby)
            {
                Log.Info($"Closing listening Socket");
                Multiplayer.ShouldReturnToJoinMenu = false;
                Multiplayer.Session.IsInLobby      = false;
                Multiplayer.LeaveGame();

                UIVirtualStarmap_Transpiler.customBirthStar   = -1;
                UIVirtualStarmap_Transpiler.customBirthPlanet = -1;

                // restore main menu if needed.
                if (GameMain.localStar.id != MainMenuStarID && MainMenuStarID != -1)
                {
                    GameMain.data.ArriveStar(GameMain.data.galaxy.StarById(MainMenuStarID));
                }

                // close planet detail view
                UIRoot.instance.uiGame.planetDetail.gameObject.SetActive(false);
            }

            // cant check anymore if we are in multiplayer or not, so just do this without check. will not do any harm C:
            RectTransform galaxySelectRect = __instance.gameObject.GetComponent <RectTransform>();

            galaxySelectRect.Find("star-count").gameObject.SetActive(true);
            galaxySelectRect.Find("resource-multiplier").gameObject.SetActive(true);
            galaxySelectRect.Find("galaxy-seed").GetComponentInChildren <InputField>().enabled = true;
            galaxySelectRect.Find("random-button").gameObject.SetActive(true);
        }
Ejemplo n.º 3
0
        static void func(UIGalaxySelect __instance, GalaxyData galaxy)
        {
            InputField seedInput = Traverse.Create(__instance).Field("seedInput").GetValue <InputField>();

            seedInput.characterLimit = 12;
            seedInput.text           = galaxy.seed.ToString("00 0000 0000");
        }
Ejemplo n.º 4
0
 public static void _OnOpen(ref UIGalaxySelect __instance)
 {
     CreateDensitySlider(__instance);
     DensityDTO.SetDensityInformation(starDensitySlider?.value);
     OnDensityChanged();
     Debug.Log("Started modifying star density");
 }
Ejemplo n.º 5
0
        static bool SeedRadom(UIGalaxySelect __instance)
        {
            GameDesc gameDesc = Traverse.Create(__instance).Field("gameDesc").GetValue <GameDesc>();

            System.Random random = Traverse.Create(__instance).Field("random").GetValue <System.Random>();
            gameDesc.galaxySeed = random.Next(int.MaxValue);
            __instance.SetStarmapGalaxy();
            return(false);
        }
 public static void Patch(ref UIGalaxySelect __instance, GalaxyData galaxy)
 {
     if (__instance.starCountSlider.minValue != desiredMinStars)
     {
         __instance.starCountSlider.minValue = desiredMinStars;
     }
     if (__instance.starCountSlider.maxValue != desiredMaxStars)
     {
         __instance.starCountSlider.maxValue = desiredMaxStars;
     }
 }
Ejemplo n.º 7
0
        public static bool OnStarCountSliderValueChange(UIGalaxySelect __instance, ref Slider ___starCountSlider,
                                                        ref GameDesc ___gameDesc, float val)
        {
            var num = (int)(___starCountSlider.value + 0.100000001490116);

            if (num == ___gameDesc.starCount)
            {
                return(false);
            }

            ___gameDesc.starCount = num;
            __instance.SetStarmapGalaxy();
            return(false);
        }
Ejemplo n.º 8
0
 public static void SetStarmapGalaxy_Postfix(UIGalaxySelect __instance)
 {
     if (Multiplayer.IsInMultiplayerMenu && Multiplayer.Session.LocalPlayer.IsHost)
     {
         // syncing players are those who have not loaded into the game yet, so they might still be in the lobby. they need to check if this packet is relevant for them in the corresponding handler.
         // just remembered others cant be in game anyways when host ist still in lobby >.>
         using (Multiplayer.Session.Network.PlayerManager.GetSyncingPlayers(out Dictionary <INebulaConnection, INebulaPlayer> syncingPlayers))
         {
             foreach (KeyValuePair <INebulaConnection, INebulaPlayer> entry in syncingPlayers)
             {
                 entry.Key.SendPacket(new LobbyUpdateValues(__instance.gameDesc.galaxyAlgo, __instance.gameDesc.galaxySeed, __instance.gameDesc.starCount, __instance.gameDesc.resourceMultiplier));
             }
         }
     }
 }
Ejemplo n.º 9
0
        public static bool EnterGame_Prefix(UIGalaxySelect __instance)
        {
            if (MainMenuManager.IsInMultiplayerMenu)
            {
                Log.Info($"Listening server on port {Config.DefaultPort}");
                var session = NebulaBootstrapper.Instance.CreateMultiplayerHostSession();
                session.StartServer(Config.DefaultPort);

                GameDesc gameDesc = AccessTools.Field(__instance.GetType(), "gameDesc").GetValue(__instance) as GameDesc;
                DSPGame.StartGameSkipPrologue(gameDesc);
                return(false);
            }

            return(true);
        }
Ejemplo n.º 10
0
        private static void CreateDensitySlider(UIGalaxySelect __instance)
        {
            TeardownDensitySlider();
            Debug.Log("Creating star density slider");

            if (uiGalaxySelect == null)
            {
                uiGalaxySelect = __instance;
            }

            // Create a new slider for star density
            if (starDensitySlider == null)
            {
                starDensitySlider = GameObject.Instantiate(__instance.starCountSlider, __instance.starCountSlider.transform);

                Vector3 newPosition = starDensitySlider.transform.position;
                newPosition.x -= 1f;
                newPosition.z += 5f;
                Vector3 newScale = starDensitySlider.transform.localScale;
                starDensitySlider.transform.position   = newPosition;
                starDensitySlider.transform.localScale = newScale;
                starDensitySlider.minValue             = 1f;
                starDensitySlider.maxValue             = 10f;
                starDensitySlider.value        = MoreOrLessDense.lastSetSliderValue.Value;
                starDensitySlider.wholeNumbers = true;
                starDensitySlider.onValueChanged.AddListener(delegate {
                    OnDensityChanged();
                });
                starDensitySliderText      = GameObject.Instantiate(__instance.starCountText, starDensitySlider.transform);
                starDensitySliderText.text = "1x";
            }

            // Create a text to go along with the slider
            if (starDensityText == null)
            {
                starDensityText = GameObject.Instantiate(__instance.starCountText, starDensitySlider.transform);
                // normally id just move this down a little bit, but moving it in the y axis causes it to vanish. Sure, why not.
                Vector3 newPosition = starDensityText.transform.position;
                Vector3 newScale    = starDensityText.transform.localScale;
                newPosition.x -= 2.5f;
                newScale.x    *= 1.6f;
                newScale.y    *= 1.6f;
                newScale.z    *= 1.6f;
                starDensityText.transform.position   = newPosition;
                starDensityText.transform.localScale = newScale;
                starDensityText.text = "Star Density";
            }
        }
Ejemplo n.º 11
0
        static bool BigSeed(UIGalaxySelect __instance)
        {
            var        _this     = __instance;
            long       num1      = -1;
            InputField seedInput = Traverse.Create(__instance).Field("seedInput").GetValue <InputField>();
            GameDesc   gameDesc  = Traverse.Create(__instance).Field("gameDesc").GetValue <GameDesc>();

            if (long.TryParse(seedInput.text, out num1))
            {
                num1 = Math.Abs(num1);
                if (num1 > int.MaxValue)
                {
                    num1 = int.MaxValue;
                }
                gameDesc.galaxySeed = (int)num1;
            }
            _this.SetStarmapGalaxy();
            return(false);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Here I just attach the Postfix to the _OnOpen method in UIGalaxySelect to overwrite the limits on the star count slider.
        /// Sadly the sliders are not named so we have to select the correct slider based on the maximum value it can hold.
        /// </summary>
        /// <param name="instance"></param>
        public static void Postfix(ref UIGalaxySelect __instance)
        {
            foreach (var child in __instance.transform.GetComponentsInChildren <Slider>())
            {
                DysonsGalaxy.Log($"Setting min star count to {DysonsGalaxyConfig.MinStarCount}");
                DysonsGalaxy.Log($"Setting max star count to {DysonsGalaxyConfig.MaxStarCount}");

                if (Math.Abs(child.maxValue - 64f) < 1f)
                {
                    child.minValue = DysonsGalaxyConfig.MinStarCount;
                    child.maxValue = DysonsGalaxyConfig.MaxStarCount;
                }
                else if (Math.Abs(child.maxValue - DysonsGalaxyConfig.MaxStarCount) < 1f)
                {
                    child.minValue = DysonsGalaxyConfig.MinStarCount;
                    child.maxValue = DysonsGalaxyConfig.MaxStarCount;
                }
            }
        }
Ejemplo n.º 13
0
        public static void _OnOpen_Postfix(UIGalaxySelect __instance)
        {
            if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsClient)
            {
                RectTransform galaxySelectRect = __instance.gameObject.GetComponent <RectTransform>();

                galaxySelectRect.Find("star-count").gameObject.SetActive(false);
                galaxySelectRect.Find("resource-multiplier").gameObject.SetActive(false);
                galaxySelectRect.Find("galaxy-seed").GetComponentInChildren <InputField>().enabled = false;
                galaxySelectRect.Find("random-button").gameObject.SetActive(false);
                galaxySelectRect.Find("property-multiplier").gameObject.SetActive(false);
                galaxySelectRect.Find("seed-key").gameObject.SetActive(false);
            }
            if (Multiplayer.IsActive)
            {
                // show lobby hints if needed
                if (Config.Options.ShowLobbyHints)
                {
                    InGamePopup.ShowInfo("The Lobby",
                                         "We changed the start of a new multiplayer game a bit and want to give you a quick overview of the new feature.\n\n" +
                                         "Clients can now join while the host is in the galaxy selection screen, and they will also land there if it is their first time connecting to the currently hosted save.\n\n" +
                                         "You can now click on any star to bring up the solar system preview. From there you can click on any planet to bring up its details.\n" +
                                         "Note that when using GalacticScale 2 this process can take a bit longer.\n\n" +
                                         "By clicking a planet while having its detail panel open you will set it as your birth planet.\n\n" +
                                         "By clicking into outer space you will go one detail level up.\n\n" +
                                         "We hope you enjoy this new feature!",
                                         "Okay, cool :)",
                                         CloseLobbyInfo);
                }
                // prepare PlanetModelingManager for the use of its compute thread as we need that for the planet details view in the lobby
                PlanetModelingManager.PrepareWorks();
                // store current star id because entering the solar system details view messes up the main menu background system.
                if (MainMenuStarID == -1)
                {
                    MainMenuStarID = GameMain.localStar.id;
                }
                Button button = GameObject.Find("UI Root/Overlay Canvas/Galaxy Select/start-button").GetComponent <Button>();
                button.interactable = true;
            }
        }
Ejemplo n.º 14
0
        public static bool Patch(ref UIGalaxySelect __instance, ref float val)
        {
            // Replicate the code of the original method
            int num = (int)(__instance.starCountSlider.value + 0.1f);

            if (num < desiredMinStars)
            {
                num = desiredMinStars;
            }
            else if (num > desiredMaxStars)
            {
                num = desiredMaxStars;
            }
            if (num != __instance.gameDesc.starCount)
            {
                __instance.gameDesc.starCount = num;
                __instance.SetStarmapGalaxy();
            }

            // Return to prevent the call of the original method
            return(false);
        }
Ejemplo n.º 15
0
        static bool MaxLenth(UIGalaxySelect __instance)
        {
            InputField seedInput = Traverse.Create(__instance).Field("seedInput").GetValue <InputField>();

            if (seedInput.isFocused && seedInput.text.Length > 12)
            {
                long num = -1;
                if (long.TryParse(seedInput.text, out num))
                {
                    if (num < 0)
                    {
                        num = -num;
                    }
                    if (num > int.MaxValue)
                    {
                        num = int.MaxValue;
                    }
                    seedInput.text = num.ToString();
                }
                seedInput.text = seedInput.text.Substring(0, 12);
            }
            return(false);
        }
Ejemplo n.º 16
0
 public static void getUIGalaxySelect(UIGalaxySelect __instance) => DSPMOD.TEST.uiGalaxySelect = __instance;
Ejemplo n.º 17
0
 public static void Postfix(UIGalaxySelect __instance, ref Slider ___starCountSlider)
 {
     ___starCountSlider.maxValue = 255;
 }
Ejemplo n.º 18
0
 public static void Postfix(UIGalaxySelect __instance, ref Slider ___starCountSlider)
 {
     ___starCountSlider.maxValue = _configStarsMax.Value;
     ___starCountSlider.minValue = _configStarsMin.Value;
 }
        public static void GalaxySelectPatch(UIGalaxySelect __instance)
        {
            var slider = Traverse.Create(__instance).Field("starCountSlider").GetValue <Slider>();

            slider.maxValue = 255;
        }
Ejemplo n.º 20
0
        public override void ProcessPacket(LobbyRequest packet, NebulaConnection conn)
        {
            if (IsClient)
            {
                return;
            }

            INebulaPlayer player;

            using (playerManager.GetPendingPlayers(out Dictionary <INebulaConnection, INebulaPlayer> pendingPlayers))
            {
                if (!pendingPlayers.TryGetValue(conn, out player))
                {
                    conn.Disconnect(DisconnectionReason.InvalidData);
                    Log.Warn("WARNING: Player tried to enter lobby without being in the pending list");
                    return;
                }

                if (GameMain.isFullscreenPaused)
                {
                    conn.Disconnect(DisconnectionReason.HostStillLoading);
                    pendingPlayers.Remove(conn);

                    return;
                }

                Dictionary <string, string> clientMods = new Dictionary <string, string>();

                using (BinaryUtils.Reader reader = new BinaryUtils.Reader(packet.ModsVersion))
                {
                    for (int i = 0; i < packet.ModsCount; i++)
                    {
                        string guid    = reader.BinaryReader.ReadString();
                        string version = reader.BinaryReader.ReadString();

                        if (!BepInEx.Bootstrap.Chainloader.PluginInfos.ContainsKey(guid))
                        {
                            conn.Disconnect(DisconnectionReason.ModIsMissingOnServer, guid);
                            pendingPlayers.Remove(conn);

                            return;
                        }

                        clientMods.Add(guid, version);
                    }
                }

                foreach (KeyValuePair <string, BepInEx.PluginInfo> pluginInfo in BepInEx.Bootstrap.Chainloader.PluginInfos)
                {
                    if (pluginInfo.Value.Instance is IMultiplayerMod mod)
                    {
                        if (!clientMods.ContainsKey(pluginInfo.Key))
                        {
                            conn.Disconnect(DisconnectionReason.ModIsMissing, pluginInfo.Key);
                            pendingPlayers.Remove(conn);

                            return;
                        }

                        string version = clientMods[pluginInfo.Key];

                        if (mod.CheckVersion(mod.Version, version))
                        {
                            continue;
                        }

                        conn.Disconnect(DisconnectionReason.ModVersionMismatch, $"{pluginInfo.Key};{version};{mod.Version}");
                        pendingPlayers.Remove(conn);

                        return;
                    }
                    else
                    {
                        foreach (BepInEx.BepInDependency dependency in pluginInfo.Value.Dependencies)
                        {
                            if (dependency.DependencyGUID == NebulaModAPI.API_GUID)
                            {
                                string hostVersion = pluginInfo.Value.Metadata.Version.ToString();
                                if (!clientMods.ContainsKey(pluginInfo.Key))
                                {
                                    conn.Disconnect(DisconnectionReason.ModIsMissing, pluginInfo.Key);
                                    pendingPlayers.Remove(conn);
                                    return;
                                }
                                if (clientMods[pluginInfo.Key] != hostVersion)
                                {
                                    conn.Disconnect(DisconnectionReason.ModVersionMismatch, $"{pluginInfo.Key};{clientMods[pluginInfo.Key]};{hostVersion}");
                                    pendingPlayers.Remove(conn);
                                    return;
                                }
                            }
                        }
                    }
                }

                if (packet.GameVersionSig != GameConfig.gameVersion.sig)
                {
                    conn.Disconnect(DisconnectionReason.GameVersionMismatch, $"{ packet.GameVersionSig };{ GameConfig.gameVersion.sig }");
                    pendingPlayers.Remove(conn);

                    return;
                }
            }

            bool isNewUser = false;

            //TODO: some validation of client cert / generating auth challenge for the client
            // Load old data of the client
            string clientCertHash = CryptoUtils.Hash(packet.ClientCert);

            using (playerManager.GetSavedPlayerData(out Dictionary <string, IPlayerData> savedPlayerData))
            {
                if (savedPlayerData.TryGetValue(clientCertHash, out IPlayerData value))
                {
                    using (playerManager.GetConnectedPlayers(out Dictionary <INebulaConnection, INebulaPlayer> connectedPlayers))
                    {
                        IPlayerData playerData = value;
                        foreach (INebulaPlayer connectedPlayer in connectedPlayers.Values)
                        {
                            if (connectedPlayer.Data == playerData)
                            {
                                playerData = value.CreateCopyWithoutMechaData();
                                Log.Warn($"Copy playerData for duplicated player{playerData.PlayerId} {playerData.Username}");
                            }
                        }
                        player.LoadUserData(playerData);
                    }
                }
                else
                {
                    // store player data once he fully loaded into the game (SyncCompleteProcessor)
                    isNewUser = true;
                }
            }

            // Add the username to the player data
            player.Data.Username = !string.IsNullOrWhiteSpace(packet.Username) ? packet.Username : $"Player {player.Id}";

            // Add the Mecha Color to the player data
            player.Data.MechaColors = packet.MechaColors;

            // if user is known and host is ingame dont put him into lobby but let him join the game
            if (!isNewUser && Multiplayer.Session.IsGameLoaded)
            {
                // Remove the new player from pending list
                using (playerManager.GetPendingPlayers(out Dictionary <INebulaConnection, INebulaPlayer> pendingPlayers))
                {
                    pendingPlayers.Remove(conn);
                }

                // Add the new player to the list
                using (playerManager.GetSyncingPlayers(out Dictionary <INebulaConnection, INebulaPlayer> syncingPlayers))
                {
                    syncingPlayers.Add(conn, player);
                }

                Multiplayer.Session.World.OnPlayerJoining(player.Data.Username);
                NebulaModAPI.OnPlayerJoinedGame?.Invoke(player.Data);

                // Make sure that each player that is currently in the game receives that a new player as join so they can create its RemotePlayerCharacter
                PlayerJoining pdata = new PlayerJoining((PlayerData)player.Data.CreateCopyWithoutMechaData()); // Remove inventory from mecha data
                using (playerManager.GetConnectedPlayers(out Dictionary <INebulaConnection, INebulaPlayer> connectedPlayers))
                {
                    foreach (KeyValuePair <INebulaConnection, INebulaPlayer> kvp in connectedPlayers)
                    {
                        kvp.Value.SendPacket(pdata);
                    }
                }

                //Add current tech bonuses to the connecting player based on the Host's mecha
                ((MechaData)player.Data.Mecha).TechBonuses = new PlayerTechBonuses(GameMain.mainPlayer.mecha);

                using (BinaryUtils.Writer p = new BinaryUtils.Writer())
                {
                    int count = 0;
                    foreach (KeyValuePair <string, BepInEx.PluginInfo> pluginInfo in BepInEx.Bootstrap.Chainloader.PluginInfos)
                    {
                        if (pluginInfo.Value.Instance is IMultiplayerModWithSettings mod)
                        {
                            p.BinaryWriter.Write(pluginInfo.Key);
                            mod.Export(p.BinaryWriter);
                            count++;
                        }
                    }

                    GameDesc gameDesc = GameMain.data.gameDesc;
                    player.SendPacket(new HandshakeResponse(gameDesc.galaxyAlgo, gameDesc.galaxySeed, gameDesc.starCount, gameDesc.resourceMultiplier, isNewUser, (PlayerData)player.Data, p.CloseAndGetBytes(), count, Config.Options.SyncSoil));
                }
            }
            else
            {
                UIGalaxySelect galaxySelect = UIRoot.instance.galaxySelect;

                using (BinaryUtils.Writer p = new BinaryUtils.Writer())
                {
                    int count = 0;
                    foreach (KeyValuePair <string, BepInEx.PluginInfo> pluginInfo in BepInEx.Bootstrap.Chainloader.PluginInfos)
                    {
                        if (pluginInfo.Value.Instance is IMultiplayerModWithSettings mod)
                        {
                            p.BinaryWriter.Write(pluginInfo.Key);
                            mod.Export(p.BinaryWriter);
                            count++;
                        }
                    }

                    if (Multiplayer.Session.IsGameLoaded)
                    {
                        GameDesc gameDesc = GameMain.data.gameDesc;
                        player.SendPacket(new LobbyResponse(gameDesc.galaxyAlgo, gameDesc.galaxySeed, gameDesc.starCount, gameDesc.resourceMultiplier, p.CloseAndGetBytes(), count));
                    }
                    else
                    {
                        player.SendPacket(new LobbyResponse(galaxySelect.gameDesc.galaxyAlgo, galaxySelect.gameDesc.galaxySeed, galaxySelect.gameDesc.starCount, galaxySelect.gameDesc.resourceMultiplier, p.CloseAndGetBytes(), count));
                    }
                }

                // Send overriden Planet and Star names
                player.SendPacket(new NameInputPacket(GameMain.galaxy, Multiplayer.Session.LocalPlayer.Id));
            }
        }
Ejemplo n.º 21
0
 public static void UIPostfix(UIGalaxySelect __instance, ref Slider ___starCountSlider)
 {
     ___starCountSlider.onValueChanged.AddListener(__instance.OnStarCountSliderValueChange);
 }
Ejemplo n.º 22
0
 public static void Patch_OnInit(UIGalaxySelect __instance, ref Slider ___starCountSlider)
 {
     ___starCountSlider.maxValue = PatchForGalaxySizeSelection.ConfigStarsMax.Value;
     ___starCountSlider.minValue = PatchForGalaxySizeSelection.ConfigStarsMin.Value;
 }