Ejemplo n.º 1
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)));
            }
        }
Ejemplo n.º 2
0
        public static async void Run()
        {
            var memory = new Mem();

            if (!memory.OpenProcess("ffxiv_dx11"))
            {
                Console.WriteLine("An error occurred opening the FFXIV process.\nPress any key to continue...");

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

            var discordManager = new Discord();

            var memoryManager = new MemoryManager(memory);

            discordManager.SetDefaultPresence();

            while (true)
            {
                discordManager.Update();
                var table = memoryManager.GetActorTable();

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

                    var territoryType = memoryManager.GetTerritoryType();

                    var placename = await XivApi.GetPlaceNameZoneForTerritoryType(territoryType);

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

                    var fcName = player.CompanyTag.Substring(0, player.CompanyTag.IndexOf("\0"));

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

                    discordManager.SetPresence(new RichPresence
                    {
                        Details = $"{player.Name.Substring(0, player.Name.IndexOf("\0"))}{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
                        }
                    });
                }
                else
                {
                    discordManager.SetDefaultPresence();
                }

                Thread.Sleep(1000);

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