Esempio n. 1
0
        public static async void Run()
        {
            var discordManager = new Discord(DefaultPresence, ClientID);

            var game = new Nhaama.FFXIV.Game(_ffxivProcess);

            Console.WriteLine(game.Process.GetSerializer().SerializeObject(game.Definitions, Formatting.Indented));

            discordManager.SetPresence(DefaultPresence);

            while (true)
            {
                if (!DoesFfxivProcessExist())
                {
                    discordManager.Deinitialize();
                    Environment.Exit(0);
                    return;
                }

                game.Update();

                if (game.ActorTable == null)
                {
                    discordManager.SetPresence(DefaultPresence);
                    continue;
                }

                if (game.ActorTable.Length > 0)
                {
                    var player = game.ActorTable[0];

                    if (player.ActorID == 0)
                    {
                        discordManager.SetPresence(DefaultPresence);
                        continue;
                    }

                    var territoryType = game.TerritoryType;

                    var loadingImageKey = await XivApi.GetLoadingImageKeyForTerritoryType(territoryType);

                    var largeImageKey = $"li_{loadingImageKey}";

                    var fcName = player.CompanyTag;

                    if (fcName != string.Empty)
                    {
                        _lastFc = fcName;
                        fcName  = $" <{fcName}>";
                    }
                    else if (_lastFc != string.Empty)
                    {
                        fcName = $" <{_lastFc}>";
                    }

                    var worldName = await XivApi.GetNameForWorld(player.World);

                    if (player.World != player.HomeWorld)
                    {
                        worldName = $"{worldName} (🏠{await XivApi.GetNameForWorld(player.HomeWorld)})";
                    }

                    discordManager.SetPresence(new RichPresence
                    {
                        Details = $"{player.Name}{fcName}",
                        State   = worldName,
                        Assets  = new Assets
                        {
                            LargeImageKey  = largeImageKey,
                            LargeImageText = await XivApi.GetPlaceNameForTerritoryType(territoryType),
                            SmallImageKey  = $"class_{player.Job}",
                            SmallImageText = await XivApi.GetJobName(player.Job) + " Lv." + player.Level
                        }
                    });
                }

                Thread.Sleep(1000);
            }
        }
        public async void DoWork(object state)
        {
            var cancellationToken = (CancellationToken)state;

            if (!Settings.IsDX11())
            {
                return;
            }

            CheckManualInstall();

            var discordManager = new DiscordPresenceManager(DefaultPresence, ClientID);

            try
            {
                var game = new Nhaama.FFXIV.Game(_gameProcess);

                discordManager.SetPresence(DefaultPresence);

                Log.Information("RichPresence DoWork started.");

                while (!cancellationToken.IsCancellationRequested)
                {
                    try
                    {
                        game.Update();
                    }
                    catch (Exception ex)
                    {
                        Log.Information(ex, "Nhaama game data update failed.");
                        Thread.Sleep(2000);
                        continue;
                    }

                    if (game.ActorTable == null)
                    {
                        discordManager.SetPresence(DefaultPresence);
                        continue;
                    }

                    if (game.ActorTable.Length > 0)
                    {
                        var player = game.ActorTable[0];

                        if (player.ActorID == 0)
                        {
                            discordManager.SetPresence(DefaultPresence);
                            continue;
                        }

                        var territoryType = game.TerritoryType;

                        var placeName       = "Hydaelyn";
                        var loadingImageKey = 1;
                        if (territoryType != 0)
                        {
                            placeName = await XivApi.GetPlaceNameForTerritoryType(territoryType);

                            loadingImageKey = await XivApi.GetLoadingImageKeyForTerritoryType(territoryType);
                        }


                        var largeImageKey = $"li_{loadingImageKey}";

                        var fcName = player.CompanyTag;

                        if (fcName != string.Empty)
                        {
                            _lastFc = fcName;
                            fcName  = $" <{fcName}>";
                        }
                        else if (_lastFc != string.Empty)
                        {
                            fcName = $" <{_lastFc}>";
                        }

                        var worldName = await XivApi.GetNameForWorld(player.World);

                        if (player.World != player.HomeWorld)
                        {
                            worldName = $"{worldName} (🏠{await XivApi.GetNameForWorld(player.HomeWorld)})";
                        }

                        discordManager.SetPresence(new RichPresence
                        {
                            Details = $"{player.Name}{fcName}",
                            State   = worldName,
                            Assets  = new Assets
                            {
                                LargeImageKey  = largeImageKey,
                                LargeImageText = placeName,
                                SmallImageKey  = $"class_{player.Job}",
                                SmallImageText = await XivApi.GetJobName(player.Job) + " Lv." + player.Level
                            }
                        });
                    }

                    Thread.Sleep(1000);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Critical error in RichPresence.");
            }
            finally
            {
                discordManager.Deinitialize();
            }

            Log.Information("RichPresence exited!");
        }
Esempio n. 3
0
        public static async void Run()
        {
            var procList = Process.GetProcessesByName("ffxiv_dx11");

            if (procList.Length == 0)
            {
                Console.WriteLine("An error occurred opening the FFXIV process: Not found.\nPress any key to continue...");

                Console.ReadKey();
                Environment.Exit(0);
            }

            var discordManager = new Discord(DefaultPresence, ClientID);

            var game = new Nhaama.FFXIV.Game(procList[0]);

            Console.WriteLine(game.Process.GetSerializer().SerializeObject(game.Definitions, Formatting.Indented));

            discordManager.SetPresence(DefaultPresence);

            while (true)
            {
                if (!DoesFfxivProcessExist())
                {
                    discordManager.Deinitialize();
                    Environment.Exit(0);
                }

                game.Update();

                if (game.ActorTable == null)
                {
                    discordManager.SetPresence(DefaultPresence);
                    continue;
                }

                if (game.ActorTable.Length > 0)
                {
                    var player = game.ActorTable[0];

                    if (player.ActorID == 0)
                    {
                        discordManager.SetPresence(DefaultPresence);
                        continue;
                    }

                    var territoryType = game.TerritoryType;

                    var placename = await XivApi.GetPlaceNameZoneForTerritoryType(territoryType);

                    var zoneAsset = "zone_" + Regex.Replace(placename.ToLower(), "[^A-Za-z0-9]", "");

                    var fcName = player.CompanyTag;

                    if (fcName != string.Empty)
                    {
                        fcName = $" <{fcName}>";
                    }

                    discordManager.SetPresence(new RichPresence
                    {
                        Details = $"{player.Name}{fcName}",
                        State   = await XivApi.GetNameForWorld(player.World),
                        Assets  = new Assets
                        {
                            LargeImageKey  = zoneAsset,
                            LargeImageText = await XivApi.GetPlaceNameForTerritoryType(territoryType),
                            SmallImageKey  = $"class_{player.Job}",
                            SmallImageText = await XivApi.GetJobName(player.Job) + " Lv." + player.Level
                        }
                    });
                }


                Thread.Sleep(1000);
            }
        }
Esempio n. 4
0
        public static async void Run()
        {
            Thread.CurrentThread.Priority = ThreadPriority.Lowest;

            var discordManager = new Discord(DefaultPresence, ClientID);

            var game    = new Nhaama.FFXIV.Game(_ffxivProcess);
            var ignores = LoadIgnoreList();

            Console.WriteLine(game.Process.GetSerializer().SerializeObject(game.Definitions, Formatting.Indented));

            discordManager.SetPresence(DefaultPresence);

            while (true)
            {
                if (!DoesFfxivProcessExist())
                {
                    discordManager.Deinitialize();
                    Environment.Exit(0);
                }

                game.Update();

                if (game.ActorTable == null)
                {
                    discordManager.SetPresence(DefaultPresence);
                    Thread.Sleep(5000);
                    continue;
                }

                if (game.ActorTable.Length > 0)
                {
                    var player = game.ActorTable[0];

                    if (player.ActorID == 0)
                    {
                        discordManager.SetPresence(DefaultPresence);
                        Thread.Sleep(5000);
                        continue;
                    }

                    var territoryType = game.TerritoryType;

                    var placename = await XivApi.GetPlaceNameZoneForTerritoryType(territoryType);

                    if (placename == "default" || placename == "Norvrandt")
                    {
                        placename = await XivApi.GetPlaceNameForTerritoryType(territoryType);
                    }

                    var zoneAsset = "zone_" + Regex.Replace(placename.ToLower(), "[^A-Za-z0-9]", "");

                    var fcName = player.CompanyTag;

                    if (fcName != string.Empty)
                    {
                        _lastFc = fcName;
                        fcName  = $" <{fcName}>";
                    }
                    else if (_lastFc != string.Empty)
                    {
                        fcName = $" <{_lastFc}>";
                    }

                    var worldName = await XivApi.GetNameForWorld(player.World);

                    if (player.World != player.HomeWorld)
                    {
                        worldName = $"{worldName} (🏠{await XivApi.GetNameForWorld(player.HomeWorld)})";
                    }

                    discordManager.SetPresence(new RichPresence
                    {
                        Details = isIgnore(player.Name) ?
                                  "** SECRET **" :
                                  $"{player.Name}{fcName}",
                        State  = worldName,
                        Assets = new Assets
                        {
                            LargeImageKey  = zoneAsset,
                            LargeImageText = await XivApi.GetPlaceNameForTerritoryType(territoryType),
                            SmallImageKey  = $"class_{player.Job}",
                            SmallImageText = await XivApi.GetJobName(player.Job) + " Lv." + player.Level
                        }
                    });
                }

                Thread.Sleep(1000);
            }

            bool isIgnore(string name)
            {
                if (ignores == null ||
                    ignores.Length < 1)
                {
                    return(false);
                }

                return(ignores.Any(x => string.Equals(x, name, StringComparison.OrdinalIgnoreCase)));
            }
        }