Пример #1
0
        /// <summary>
        /// Activates a view into a specific <see cref="IRegion" /> via <see cref="IRegionManager" /> from a given view model.
        /// </summary>
        /// <param name="viewModel">The view model.</param>
        /// <param name="parentViewModel">The parent view model.</param>
        /// <param name="regionName">The region name.</param>
        /// <exception cref="InvalidOperationException">If <paramref name="regionName" /> is <c>null</c> and the <paramref name="viewModel" /> was no show at least one time in a <see cref="IRegion" />.</exception>
        /// <exception cref="InvalidOperationException">If <paramref name="regionName" /> is <c>null</c> and the <paramref name="viewModel" /> was no show at least one time in a <see cref="IRegion" />.</exception>
        /// <exception cref="InvalidOperationException">If <paramref name="regionName" /> is <c>null</c> and the <paramref name="viewModel" /> was no show at least one time in a <see cref="IRegion" />.</exception>
        /// <exception cref="System.InvalidOperationException">The <paramref name="viewModel" /> and <paramref name="parentViewModel" /> are equals.</exception>
        /// <exception cref="NotSupportedException">If the implementation of IRegionManager is not registered in the IoC container</exception>
        /// <exception cref="System.ArgumentNullException">The <paramref name="viewModel" /> is <c>null</c>.</exception>
        /// <exception cref="System.ArgumentNullException">The <paramref name="viewModel" /> is <c>null</c>.</exception>
        /// <exception cref="System.ArgumentException">The <paramref name="regionName" /> is <c>null</c> or whitespace.</exception>
        /// <exception cref="System.ArgumentNullException">The <paramref name="viewModel" /> is <c>null</c>.</exception>
        public void Activate(IViewModel viewModel, IViewModel parentViewModel, string regionName)
        {
            Argument.IsNotNull(() => viewModel);
            Argument.IsNotNull(() => parentViewModel);
            Argument.IsNotNullOrWhitespace(() => regionName);

            if (ReferenceEquals(viewModel, parentViewModel))
            {
                var exception = new InvalidOperationException(ReferenceEqualsInvalidOperationExceptionMessage);

                Log.Error(exception);

                throw exception;
            }

            IView[]     viewsOfParentViewModel = this._viewManager.GetViewsOfViewModel(parentViewModel);
            IRegionInfo regionInfo             = viewsOfParentViewModel.OfType <DependencyObject>().Select(dependencyObject => dependencyObject.GetRegionInfo(regionName)).FirstOrDefault(info => info != null);

            if (regionInfo != null)
            {
                this.Activate(viewModel, regionInfo);

                if (parentViewModel is IRelationalViewModel)
                {
                    (parentViewModel as IRelationalViewModel).RegisterChildViewModel(viewModel);
                }

                if (viewModel is IRelationalViewModel)
                {
                    (viewModel as IRelationalViewModel).SetParentViewModel(parentViewModel);
                }
            }
        }
Пример #2
0
            public static bool Prefix(ref RegionMenu __instance)
            {
                ClearOnClickAction(__instance.ButtonPool);

                CustomServerInfo customServer = new CustomServerInfo("FloofUs", "77.55.217.159", 22023);

                customServers.Add(customServer);

                if (ServerManager.DefaultRegions.Count != 3 + customServers.Count || forceReloadServers)
                {
                    var regions = new IRegionInfo[3 + customServers.Count];



                    for (int i = 0; i < 3; i++)
                    {
                        regions[i] = _defaultRegions[i];
                    }

                    for (int i = 0; i < customServers.Count; i++)
                    {
                        Il2CppReferenceArray <ServerInfo> servers = new [] { new ServerInfo(customServers[i].name, customServers[i].ip, (ushort)customServers[i].port) };

                        regions[i + 3] = new DnsRegionInfo(customServers[i].ip, customServers[i].name, StringNames.NoTranslation, servers).Cast <IRegionInfo>();
                    }

                    ServerManager.DefaultRegions            = regions;
                    ServerManager.Instance.AvailableRegions = regions;
                    ServerManager.Instance.SaveServers();
                }

                return(true);
            }
            public static bool Prefix(RegionMenu __instance, [HarmonyArgument(0)] IRegionInfo region)
            {
                if (region.PingServer == "Manage servers...")
                {
                    if (_managementForm == null || _managementForm.IsDisposed)
                    {
                        _managementForm = new ServersManagementForm();
                    }

                    _managementForm.regionMenu = __instance;

                    if (_managementForm.Visible)
                    {
                        _managementForm.Focus();
                    }
                    else
                    {
                        _managementForm.ShowDialog();
                    }

                    return(false);
                }
                else
                {
                    return(true);
                }
            }
Пример #4
0
    public IProfile SetupProfile(string profileName, bool persist = true)
    {
        IProfile?existingProfile = _profileManager.GetProfile(profileName);

        if (existingProfile != null)
        {
            return(existingProfile);
        }

start:

        string enteredKeyId = GetKeyId();

        byte[]      accessKey = GetAccessKey();
        IRegionInfo region    = GetRegion();

        Console.WriteLine();
        Console.WriteLine("Please confirm the following information:");
        Console.WriteLine("Key id: " + enteredKeyId);
        Console.WriteLine("Region: " + region.Code + " -- " + region.Name);
        Console.WriteLine();

        ConsoleKey key;

        do
        {
            Console.WriteLine("Is it correct? Y/N");

            key = Console.ReadKey(true).Key;
        } while (key != ConsoleKey.Y && key != ConsoleKey.N);

        if (key == ConsoleKey.N)
        {
            goto start;
        }

        IProfile profile = _profileManager.CreateProfile(profileName, enteredKeyId, accessKey, region.Code, persist);

        if (persist)
        {
            if (!string.IsNullOrEmpty(profile.Location))
            {
                Console.WriteLine("Successfully saved the profile to " + profile.Location);
            }
            else
            {
                Console.WriteLine("Successfully saved profile");
            }
        }

        //Clear the access key from memory
        Array.Clear(accessKey, 0, accessKey.Length);

        return(profile);
    }
Пример #5
0
        /// <summary>
        /// Checks if the dependency object contains a <see cref="IRegion"/> with the name received as parameter.
        /// </summary>
        /// <param name="this">
        /// The dependency object.
        /// </param>
        /// <param name="regionName">
        /// The region name.
        /// </param>
        /// <param name="serviceLocator">
        /// The service locator.
        /// </param>
        /// <param name="defaultRegionManager">
        /// The default region manager.
        /// </param>
        /// <returns>
        /// The <see cref="IRegionInfo"/> if the view or nested visual nodes contains a region with the given name, otherwise <c>null</c>.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">The <paramref name="this"/> is <c>null</c>.</exception>
        /// <exception cref="System.ArgumentException">The <paramref name="regionName"/> is <c>null</c> or whitespace.</exception>
        /// <remarks>
        /// This method also ensures the setup of the same <see cref="IRegionManager"/> through the visual tree.<br/>
        /// - If the dependency object has no a region manager the <paramref name="defaultRegionManager"/> will be set. <br/>
        /// - If a parent dependency object of the give <paramref name="this"/> instance have a established <see cref="IRegionManager"/> then the <paramref name="defaultRegionManager" /> will be ignored.<br/>
        /// </remarks>
        public static IRegionInfo GetRegionInfo(this DependencyObject @this, string regionName, IServiceLocator serviceLocator = null, IRegionManager defaultRegionManager = null)
        {
            Argument.IsNotNull("@this", @this);
            Argument.IsNotNullOrWhitespace("regionName", regionName);

            serviceLocator = serviceLocator ?? ServiceLocator.Default;

            IRegionInfo regionInfo = null;

            var queue = new Queue <DependencyObject>();

            queue.Enqueue(@this);

            defaultRegionManager = @this.GetRegionManager() ?? @this.FindFirstParentRegionManager() ?? defaultRegionManager;

            IRegionManager regionManager = null;

            do
            {
                var current = queue.Dequeue();

                string currentRegionName = current.GetRegionName();
                if (regionManager == null && !string.IsNullOrEmpty(currentRegionName) && (regionManager = current.GetRegionManager()) == null)
                {
                    current.SetRegionManager(regionManager = defaultRegionManager ?? serviceLocator.ResolveType <IRegionManager>().CreateRegionManager());
                }

                if (currentRegionName == regionName)
                {
                    if (regionManager != null)
                    {
                        current.SetRegionManager(regionManager);
                    }

                    regionInfo = new RegionInfo(current);
                }
                else
                {
                    int childrenCount = VisualTreeHelper.GetChildrenCount(current);
                    for (int i = 0; i < childrenCount; i++)
                    {
                        queue.Enqueue(VisualTreeHelper.GetChild(current, i));
                    }
                }
            }while (regionInfo == null && queue.Count > 0);

            return(regionInfo);
        }
Пример #6
0
        public static bool SetDirectRegion(string ip, out IRegionInfo newRegion)
        {
            newRegion = null;

            if (!Regex.IsMatch(ip, @"^(\d{1,3}\.){3}\d{1,3}$"))
            {
                return(false);
            }

            newRegion = new DnsRegionInfo(ip, ip, StringNames.NoTranslation, ip, 22023)
                        .Cast <IRegionInfo>();

            RegionsPatch.DirectRegion = newRegion;
            RegionsPatch.Patch();

            return(true);
        }
            public static bool Prefix(ref RegionMenu __instance)
            {
                ClearOnClickAction(__instance.ButtonPool);

                Directory.CreateDirectory(CustomServersPlugin.userDataPath);

                if (File.Exists(Path.Combine(CustomServersPlugin.userDataPath, CustomServersPlugin.customServersFilePath)))
                {
                    customServers = JsonConvert.DeserializeObject <List <CustomServerInfo> >(File.ReadAllText(Path.Combine(CustomServersPlugin.userDataPath, CustomServersPlugin.customServersFilePath)));
                    CustomServersPlugin.Logger.LogDebug("Loaded custom servers list from file!");
                }
                else
                {
                    CustomServersPlugin.Logger.LogWarning("Custom servers list file not found!");
                }

                if (ServerManager.DefaultRegions.Count != 4 + customServers.Count || forceReloadServers)
                {
                    var regions = new IRegionInfo[4 + customServers.Count];

                    regions[0] = new DnsRegionInfo("Manage servers...", "Manage servers...", StringNames.NoTranslation,
                                                   "Manage servers...").Cast <IRegionInfo>();

                    for (int i = 0; i < 3; i++)
                    {
                        regions[i + 1] = _defaultRegions[i];
                    }

                    for (int i = 0; i < customServers.Count; i++)
                    {
                        Il2CppReferenceArray <ServerInfo> servers = new ServerInfo[1] {
                            new ServerInfo(customServers[i].name, customServers[i].ip, (ushort)customServers[i].port)
                        };

                        regions[i + 4] = new DnsRegionInfo(customServers[i].ip, customServers[i].name, StringNames.NoTranslation, servers).Cast <IRegionInfo>();
                    }

                    ServerManager.DefaultRegions            = regions;
                    ServerManager.Instance.AvailableRegions = regions;
                    ServerManager.Instance.SaveServers();
                }

                return(true);
            }
Пример #8
0
        /// <summary>
        /// Activates a view into a specific <see cref="IRegion"/> via <see cref="IRegionManager"/> from a given view model.
        /// </summary>
        /// <param name="this">
        /// The <see cref="IUIVisualizerService"/> service self instance.
        /// </param>
        /// <param name="viewModel">
        /// The view model.
        /// </param>
        /// <param name="parentViewModel">
        /// The parent view model.
        /// </param>
        /// <param name="regionName">
        /// The region name.
        /// </param>
        /// <exception cref="InvalidOperationException">
        /// If <paramref name="regionName"/> is <c>null</c> and the <paramref name="viewModel"/> was no show at least one time in a <see cref="IRegion"/>.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// If the view that belongs to the <paramref name="viewModel"/> is already the logical child of another element.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// If the implementation of <see cref="IRegionManager"/> is not registered in the IoC container.
        /// </exception>
        /// <exception cref="System.InvalidOperationException">
        /// The <paramref name="viewModel"/> and <paramref name="parentViewModel"/> are equals.
        /// </exception>
        /// <exception cref="NotSupportedException">
        /// If the implementation of IRegionManager is not registered in the IoC container
        /// </exception>
        /// <exception cref="System.ArgumentNullException">
        /// The <paramref name="viewModel"/> is <c>null</c>.
        /// </exception>
        /// <exception cref="System.ArgumentNullException">
        /// The <paramref name="parentViewModel"/> is <c>null</c>.
        /// </exception>
        /// <exception cref="System.ArgumentException">
        /// The <paramref name="regionName"/> is <c>null</c> or whitespace.
        /// </exception>
        /// <exception cref="System.ArgumentNullException">
        /// The <paramref name="this"/> is <c>null</c>.
        /// </exception>
        public static void Activate(this IUIVisualizerService @this, IViewModel viewModel, IViewModel parentViewModel, string regionName)
        {
            Argument.IsNotNull("@this", @this);
            Argument.IsNotNull("viewModel", viewModel);
            Argument.IsNotNull("parentViewModel", parentViewModel);
            Argument.IsNotNullOrWhitespace("regionName", regionName);

            if (ReferenceEquals(viewModel, parentViewModel))
            {
                var exception = new InvalidOperationException(ReferenceEqualsInvalidOperationExceptionMessage);

                Log.Error(exception);

                throw exception;
            }

            var serviceLocator = viewModel.GetService <IServiceLocator>();

            var viewManager = serviceLocator.ResolveType <IViewManager>();

            IView[]     viewsOfParentViewModel = viewManager.GetViewsOfViewModel(parentViewModel);
            IRegionInfo regionInfo             = viewsOfParentViewModel.OfType <DependencyObject>().Select(dependencyObject => dependencyObject.GetRegionInfo(regionName, serviceLocator)).FirstOrDefault(info => info != null);

            if (regionInfo != null)
            {
                Activate(viewModel, regionInfo);

                if (parentViewModel is IRelationalViewModel)
                {
                    (parentViewModel as IRelationalViewModel).RegisterChildViewModel(viewModel);
                }

                if (viewModel is IRelationalViewModel)
                {
                    (viewModel as IRelationalViewModel).SetParentViewModel(parentViewModel);
                }
            }
        }
Пример #9
0
        public static IRegionInfo AddRegion(string name, string ip, ushort port)
        {
            if (Uri.CheckHostName(ip) != UriHostNameType.IPv4)
            {
                return(ServerManager.Instance.CurrentRegion);
            }

            IRegionInfo existingRegion =
                ServerManager.DefaultRegions.ToArray().FirstOrDefault(region => region.PingServer == ip);

            if (existingRegion != null)
            {
                return(existingRegion);
            }

            IRegionInfo newRegion = new DnsRegionInfo(ip, name, StringNames.NoTranslation, ip, port)
                                    .Cast <IRegionInfo>();

            RegionsPatch.ModRegions.Add(newRegion);
            RegionsPatch.Patch();

            return(newRegion);
        }
Пример #10
0
 /// <summary>
 /// Activates a view into a specific <see cref="IRegion" /> from a given view model and the <see cref="IRegionInfo"/>.
 /// </summary>
 /// <param name="viewModel">The view model</param>
 /// <param name="regionInfo">The region info</param>
 private void Activate(IViewModel viewModel, IRegionInfo regionInfo)
 {
     Activate(viewModel, regionInfo.RegionName, regionInfo.RegionManager);
 }
Пример #11
0
            internal static void RefreshRegionMenu()
            {
                if (!GameObject.Find("RegionMenu"))
                {
                    return;
                }

                var regionButtons = DestroyableSingleton <RegionMenu> .Instance.ButtonPool.activeChildren.ToArray();

                var defaultRegions = ServerManager.DefaultRegions;
                var showOfficials  = UnifyPlugin.ShowOfficialRegions.Value;
                var showExtras     = UnifyPlugin.ShowExtraRegions.Value;

                for (int i = 0; i < regionButtons.Length; i++)
                {
                    ServerListButton regionButton = regionButtons[i].Cast <ServerListButton>();
                    IRegionInfo      region       = defaultRegions[i];

                    var textTranslatorTemp = regionButton.GetComponentInChildren <TextTranslatorTMP>();
                    if (textTranslatorTemp)
                    {
                        textTranslatorTemp.Destroy();
                    }

                    int   extraRegionCount   = OldRegions.Length + NewRegions.Length + ModRegions.Count;
                    bool  isCustomRegion     = i >= OldRegions.Length;
                    bool  isCustomUserRegion = i >= extraRegionCount;
                    float x = (!isCustomRegion && !showExtras ? 3f : 0) + (isCustomRegion ? 3f : 0) +
                              (isCustomUserRegion ? 3f : 0) - 4.25f - (!showOfficials || OldRegions.Length == 0 ? 1.5f : 0) -
                              (!showExtras || extraRegionCount == 0 ? 1.5f : 0);
                    float y = i - (isCustomRegion ? OldRegions.Length : 0) -
                              (isCustomUserRegion ? NewRegions.Length + ModRegions.Count : 0);

                    var regionButtonPosition = new Vector3(1.25f + x, 2f - 0.5f * y, 0);
                    regionButton.transform.localPosition = regionButtonPosition;

                    regionButton.gameObject.SetActive(
                        (showOfficials || i >= OldRegions.Length) &&
                        (showExtras || !isCustomRegion || isCustomUserRegion));

                    var buttonRolloverHandler = regionButton.GetComponent <ButtonRolloverHandler>();

                    if (RegionsEditor.IsActive)
                    {
                        buttonRolloverHandler.OverColor =
                            ServerManager.Instance.CurrentRegion.Name == region.Name ? Color.white : Color.black;
                        regionButton.Text.color = Color.gray;
                    }
                    else
                    {
                        buttonRolloverHandler.OverColor = Color.green;
                        regionButton.Text.color         = Color.white;
                    }

                    if (isCustomUserRegion)
                    {
                        regionButton.Text.text =
                            RegionsEditor.IsActive ? $"{region.Name}\n{region.PingServer}   {region.Servers[0].Port}" :
                            region.Name;
                    }
                }
            }