Esempio n. 1
0
        public unsafe void Initialize(DalamudPluginInterface pluginInterface)
        {
            Interface = pluginInterface;

            Configuration = pluginInterface.GetPluginConfig() as JobIconsConfiguration ?? new JobIconsConfiguration();

            Address = new PluginAddressResolver();
            Address.Setup(pluginInterface.TargetModuleScanner);

            XivApi.Initialize(Interface, Address);
            IconSet.Initialize(this);

            SetNamePlateHook = new Hook <SetNamePlateDelegate>(Address.AddonNamePlate_SetNamePlatePtr, new SetNamePlateDelegate(SetNamePlateDetour), this);
            SetNamePlateHook.Enable();

            EmptySeStringPtr = XivApi.StringToSeStringPtr("");

            var commandInfo = new CommandInfo(CommandHandler)
            {
                HelpMessage = "Opens Job Icons config.",
                ShowInHelp  = true
            };

            Interface.CommandManager.AddHandler(Command1, commandInfo);
            Interface.CommandManager.AddHandler(Command2, commandInfo);

            Task.Run(() => FixNamePlates(FixNonPlayerCharacterNamePlatesTokenSource.Token));

            PluginGui = new JobIconsGui(this);
        }
Esempio n. 2
0
        public void Dispose()
        {
            Interface.CommandManager.RemoveHandler(Command1);
            Interface.CommandManager.RemoveHandler(Command2);

            PluginGui.Dispose();

            SetNamePlateHook.Disable();
            SetNamePlateHook.Dispose();

            XivApi.DisposeInstance();
            FixNonPlayerCharacterNamePlatesTokenSource.Cancel();
            Marshal.FreeHGlobal(EmptySeStringPtr);
        }
Esempio n. 3
0
        private void FixNamePlates()
        {
            var addon = XivApi.GetSafeAddonNamePlate();

            for (int i = 0; i < 50; i++)
            {
                var npObject = addon.GetNamePlateObject(i);
                if (npObject == null || !npObject.IsVisible)
                {
                    continue;
                }

                var npInfo = npObject.NamePlateInfo;
                if (npInfo == null)
                {
                    continue;
                }

                var actorID = npInfo.Data.ActorID;
                if (actorID == -1)
                {
                    continue;
                }

                var isPC             = npInfo.IsPlayerCharacter();
                var isLocalPlayer    = npObject.IsLocalPlayer;
                var isPartyMember    = npInfo.IsPartyMember();
                var isAllianceMember = npInfo.IsAllianceMember();

                var updateLocalPlayer    = Configuration.SelfIcon && isLocalPlayer;
                var updatePartyMember    = Configuration.PartyIcons && isPartyMember;
                var updateAllianceMember = Configuration.AllianceIcons && isAllianceMember;
                var updateEveryoneElse   = Configuration.EveryoneElseIcons && !isLocalPlayer && !isPartyMember && !isAllianceMember;

                if (!isPC || !(updateLocalPlayer || updatePartyMember || updateAllianceMember || updateEveryoneElse))
                {
                    npObject.SetIconScale(1);
                }
            }
        }
Esempio n. 4
0
        private void UpdateNamePlates()
        {
            // So this doesn't work quite... exactly. Something else updates the NamePlate
            // and resizes things which makes this cause objects to jump around.

            if (Configuration.Enabled)
            {
                var addon = XivApi.GetSafeAddonNamePlate();
                for (int i = 0; i < 50; i++)
                {
                    var npObject = addon.GetNamePlateObject(i);
                    if (npObject == null || !npObject.IsVisible)
                    {
                        continue;
                    }

                    var npInfo = npObject.NamePlateInfo;
                    if (npInfo == null)
                    {
                        continue;
                    }

                    var actorID = npInfo.Data.ActorID;
                    if (actorID == -1)
                    {
                        continue;
                    }

                    if (!npInfo.IsPlayerCharacter())  // Only PlayerCharacters can have icons
                    {
                        continue;
                    }

                    var jobID = npInfo.GetJobID();
                    if (jobID < 1 || jobID >= Enum.GetValues(typeof(Job)).Length)
                    {
                        continue;
                    }

                    var isLocalPlayer    = XivApi.IsLocalPlayer(actorID);
                    var isPartyMember    = XivApi.IsLocalPlayer(actorID);
                    var isAllianceMember = XivApi.IsAllianceMember(actorID);

                    var updateLocalPlayer    = Configuration.SelfIcon && isLocalPlayer;
                    var updatePartyMember    = Configuration.PartyIcons && isPartyMember;
                    var updateAllianceMember = Configuration.AllianceIcons && isAllianceMember;
                    var updateEveryoneElse   = Configuration.EveryoneElseIcons && !isLocalPlayer && !isPartyMember && !isAllianceMember;

                    if (updateLocalPlayer || updatePartyMember || updateAllianceMember || updateEveryoneElse)
                    {
                        var iconSet = Configuration.GetIconSet(jobID);
                        // var iconID = iconSet.GetIconID(jobID);
                        var scaleMult = iconSet.ScaleMultiplier;

                        npObject.SetIconScale(Configuration.Scale * scaleMult);
                        npObject.SetIconPosition(Configuration.XAdjust, Configuration.YAdjust);

                        //var isPrefixTitle = npInfo.Data.IsPrefixTitle;

                        // I couldn't find this in the NamePlateInfo, it'll fix itself the next time SetNamePlate is called by the game.
                        //var displayTitle = true;


                        // plugin.SetNamePlateDetour(npObject.Pointer, isPrefixTitle, displayTitle, npInfo.TitleAddress, npInfo.NameAddress, npInfo.FcNameAddress, iconID);

                        //var title = Encoding.UTF8.GetBytes(Marshal.PtrToStringAnsi(new IntPtr(npi->DisplayTitle.StringPtr)));
                        //var name = Encoding.UTF8.GetBytes(Marshal.PtrToStringAnsi(new IntPtr(npi->Name.StringPtr)));
                        //var fcName = Encoding.UTF8.GetBytes(Marshal.PtrToStringAnsi(new IntPtr(npi->FcName.StringPtr)));

                        //var titlePtr = Marshal.AllocHGlobal(title.Length + 1);
                        //var namePtr = Marshal.AllocHGlobal(name.Length + 1);
                        //var fcNamePtr = Marshal.AllocHGlobal(fcName.Length + 1);

                        //Marshal.Copy(title, 0, titlePtr, title.Length);
                        //Marshal.Copy(name, 0, namePtr, name.Length);
                        //Marshal.Copy(fcName, 0, fcNamePtr, fcName.Length);

                        //Marshal.WriteByte(titlePtr + title.Length, 0);
                        //Marshal.WriteByte(namePtr + name.Length, 0);
                        //Marshal.WriteByte(fcNamePtr + fcName.Length, 0);

                        //plugin.SetNamePlateDetour(npObject.Pointer, isPrefixTitle, displayTitle, titlePtr, namePtr, fcNamePtr, iconID);

                        //Marshal.FreeHGlobal(titlePtr);
                        //Marshal.FreeHGlobal(namePtr);
                        //Marshal.FreeHGlobal(fcNamePtr);
                    }
                }
            }
        }
Esempio n. 5
0
        private void OnBuildUi_Debug()
        {
            if (isImguiDebugOpen)
            {
                ImGui.SetNextWindowSize(new Vector2(500, 500), ImGuiCond.FirstUseEver);
                if (ImGui.Begin("JobIcons Debug", ref isImguiDebugOpen))
                {
                    ImGui.PushItemWidth(-1);

                    if (ImGui.CollapsingHeader("PartyMembers"))
                    {
                        var headers = new string[] { "Address", "ActorID", "Name", "IsLocalPlayer", "IsParty", "isPC" };
                        var sizes   = new float[headers.Length];

                        ImGui.Columns(headers.Length);
                        for (int i = 0; i < headers.Length; i++)
                        {
                            DebugTableCell(headers[i], sizes);
                        }

                        ImGui.Separator();

                        foreach (var actor in plugin.Interface.ClientState.Actors)
                        {
                            var isLocalPlayer = XivApi.IsLocalPlayer(actor.ActorId);
                            var isParty       = XivApi.IsPartyMember(actor.ActorId);
                            var isPC          = actor is Dalamud.Game.ClientState.Actors.Types.PlayerCharacter;
                            if (isLocalPlayer || isParty)
                            {
                                DebugTableCell($"0x{actor.Address.ToInt64():X}", sizes);
                                DebugTableCell(actor.ActorId.ToString(), sizes);
                                DebugTableCell(actor.Name, sizes);
                                DebugTableCell(isLocalPlayer.ToString(), sizes);
                                DebugTableCell(isParty.ToString(), sizes);
                                DebugTableCell(isPC.ToString(), sizes);
                            }
                        }

                        for (int i = 0; i < sizes.Length; i++)
                        {
                            ImGui.SetColumnWidth(i, sizes[i] + 20);
                        }

                        ImGui.Columns(1);
                        ImGui.NewLine();
                    }

                    if (ImGui.CollapsingHeader("NamePlateObjects"))
                    {
                        var addon = XivApi.GetSafeAddonNamePlate();
                        if (addon.Pointer == IntPtr.Zero)
                        {
                            ImGui.Text("Addon not available");
                            ImGui.NewLine();
                        }
                        else
                        {
                            var headers = new string[] {
                                "Index",
                                "npObj", "Visible", "isLocalPlayer", "Layer", "XAdjust", "YAdjust", "XPos", "YPos", "XScale", "YScale", "Type",
                                "npInfo", "ActorID", "Name", "isPC", "isParty", "isAlliance", "JobID", "PrefixTitle", "Title", "FcName", "LevelText"
                            };
                            var sizes = new float[headers.Length];

                            ImGui.Columns(headers.Length);

                            for (int i = 0; i < headers.Length; i++)
                            {
                                DebugTableCell(headers[i], sizes);
                            }

                            ImGui.Separator();

                            for (int i = 0; i < 50; i++)
                            {
                                var npObject = addon.GetNamePlateObject(i);
                                if (npObject == null)
                                {
                                    for (int c = 0; c < headers.Length; c++)
                                    {
                                        DebugTableCell("npObj=null", sizes);
                                    }
                                    continue;
                                }

                                var npInfo = npObject.NamePlateInfo;
                                if (npInfo == null)
                                {
                                    for (int c = 0; c < headers.Length; c++)
                                    {
                                        DebugTableCell("npInfo=null", sizes);
                                    }
                                    continue;
                                }

                                var    imageNode = npObject.IconImageNode;
                                string imageX, imageY, scaleX, scaleY;

                                imageX = imageNode.AtkResNode.X.ToString();
                                imageY = imageNode.AtkResNode.Y.ToString();
                                scaleX = imageNode.AtkResNode.ScaleX.ToString();
                                scaleY = imageNode.AtkResNode.ScaleY.ToString();

                                DebugTableCell(i.ToString(), sizes);
                                DebugTableCell($"0x{npObject.Pointer.ToInt64():X}", sizes);
                                DebugTableCell(npObject.IsVisible.ToString(), sizes);
                                DebugTableCell(npObject.IsLocalPlayer.ToString(), sizes);
                                DebugTableCell(npObject.Data.Layer.ToString(), sizes);
                                DebugTableCell(npObject.Data.IconXAdjust.ToString(), sizes);
                                DebugTableCell(npObject.Data.IconYAdjust.ToString(), sizes);
                                DebugTableCell(imageX, sizes);
                                DebugTableCell(imageY, sizes);
                                DebugTableCell(scaleX, sizes);
                                DebugTableCell(scaleY, sizes);
                                DebugTableCell(npObject.Data.NameplateKind.ToString(), sizes);

                                DebugTableCell($"0x{npInfo.Pointer.ToInt64():X}", sizes);
                                DebugTableCell(npInfo.Data.ActorID.ToString(), sizes);
                                DebugTableCell(npInfo.Name, sizes);
                                DebugTableCell(XivApi.IsPlayerCharacter(npInfo.Data.ActorID).ToString(), sizes);
                                DebugTableCell(XivApi.IsPartyMember(npInfo.Data.ActorID).ToString(), sizes);
                                DebugTableCell(XivApi.IsAllianceMember(npInfo.Data.ActorID).ToString(), sizes);
                                DebugTableCell(XivApi.GetJobId(npInfo.Data.ActorID).ToString(), sizes);
                                DebugTableCell(npInfo.Data.IsPrefixTitle.ToString(), sizes);
                                DebugTableCell(npInfo.Title, sizes);
                                DebugTableCell(npInfo.FcName, sizes);
                                DebugTableCell(npInfo.LevelText, sizes);
                            }

                            for (int i = 0; i < sizes.Length; i++)
                            {
                                ImGui.SetColumnWidth(i, sizes[i] + 20);
                            }

                            ImGui.Columns(1);
                            ImGui.NewLine();
                        }
                    }

                    ImGui.PopItemWidth();
                }
                ImGui.End();
            }
        }
Esempio n. 6
0
 public bool IsAllianceMember() => XivApi.IsAllianceMember(Data.ActorID);
Esempio n. 7
0
 public bool IsPartyMember() => XivApi.IsPartyMember(Data.ActorID);
Esempio n. 8
0
 public bool IsPlayerCharacter() => XivApi.IsPlayerCharacter(Data.ActorID);