Compare commits

..

10 Commits
v0.7 ... master

27 changed files with 1773 additions and 328 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "LLib"]
path = LLib
url = https://git.carvel.li/liza/LLib

3
Gearsetter.IpcTest/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
/dist
/obj
/bin

View File

@ -0,0 +1,8 @@
<Project Sdk="Dalamud.NET.Sdk/9.0.2">
<PropertyGroup>
<Version>1.0</Version>
<OutputPath>dist</OutputPath>
</PropertyGroup>
<Import Project="..\LLib\LLib.targets"/>
</Project>

View File

@ -0,0 +1,6 @@
{
"Name": "Gearsetter (IPC Test)",
"Author": "Liza Carvelli",
"Punchline": "dev only plugin",
"Description": "dev only plugin"
}

View File

@ -0,0 +1,47 @@
using System.Collections.Generic;
using Dalamud.Game.Command;
using Dalamud.Plugin;
using Dalamud.Plugin.Services;
using FFXIVClientStructs.FFXIV.Client.Game;
using FFXIVClientStructs.FFXIV.Client.UI.Misc;
namespace Gearsetter.IpcTest;
public class GearsetterIpcTestPlugin : IDalamudPlugin
{
private readonly IDalamudPluginInterface _pluginInterface;
private readonly ICommandManager _commandManager;
private readonly IChatGui _chatGui;
public GearsetterIpcTestPlugin(IDalamudPluginInterface pluginInterface, ICommandManager commandManager,
IChatGui chatGui)
{
_pluginInterface = pluginInterface;
_commandManager = commandManager;
_chatGui = chatGui;
_commandManager.AddHandler("/recommendedgear", new CommandInfo(ProcessCommand));
}
private unsafe void ProcessCommand(string command, string arguments)
{
int currentGearsetIndex = RaptureGearsetModule.Instance()->CurrentGearsetIndex;
var recommendations = _pluginInterface
.GetIpcSubscriber<byte, List<(uint ItemId, InventoryType? SourceInventory, byte? SourceInventorySlot, RaptureGearsetModule.GearsetItemIndex TargetSlot)>>(
"Gearsetter.GetRecommendationsForGearset").InvokeFunc((byte)currentGearsetIndex);
if (recommendations.Count == 0)
_chatGui.Print($"No recommendations for gearset #{currentGearsetIndex}.");
else
{
foreach (var recommendation in recommendations)
_chatGui.Print(
$"Recommendation: Equip item {recommendation.ItemId} from {recommendation.SourceInventory} (slot {recommendation.SourceInventorySlot}) as {recommendation.TargetSlot}");
}
}
public void Dispose()
{
_commandManager.RemoveHandler("/recommendedgear");
}
}

View File

@ -0,0 +1,87 @@
{
"version": 1,
"dependencies": {
"net8.0-windows7.0": {
"DalamudPackager": {
"type": "Direct",
"requested": "[2.1.13, )",
"resolved": "2.1.13",
"contentHash": "rMN1omGe8536f4xLMvx9NwfvpAc9YFFfeXJ1t4P4PE6Gu8WCIoFliR1sh07hM+bfODmesk/dvMbji7vNI+B/pQ=="
},
"DotNet.ReproducibleBuilds": {
"type": "Direct",
"requested": "[1.1.1, )",
"resolved": "1.1.1",
"contentHash": "+H2t/t34h6mhEoUvHi8yGXyuZ2GjSovcGYehJrS2MDm2XgmPfZL2Sdxg+uL2lKgZ4M6tTwKHIlxOob2bgh0NRQ==",
"dependencies": {
"Microsoft.SourceLink.AzureRepos.Git": "1.1.1",
"Microsoft.SourceLink.Bitbucket.Git": "1.1.1",
"Microsoft.SourceLink.GitHub": "1.1.1",
"Microsoft.SourceLink.GitLab": "1.1.1"
}
},
"Microsoft.SourceLink.Gitea": {
"type": "Direct",
"requested": "[8.0.0, )",
"resolved": "8.0.0",
"contentHash": "KOBodmDnlWGIqZt2hT47Q69TIoGhIApDVLCyyj9TT5ct8ju16AbHYcB4XeknoHX562wO1pMS/1DfBIZK+V+sxg==",
"dependencies": {
"Microsoft.Build.Tasks.Git": "8.0.0",
"Microsoft.SourceLink.Common": "8.0.0"
}
},
"Microsoft.Build.Tasks.Git": {
"type": "Transitive",
"resolved": "8.0.0",
"contentHash": "bZKfSIKJRXLTuSzLudMFte/8CempWjVamNUR5eHJizsy+iuOuO/k2gnh7W0dHJmYY0tBf+gUErfluCv5mySAOQ=="
},
"Microsoft.SourceLink.AzureRepos.Git": {
"type": "Transitive",
"resolved": "1.1.1",
"contentHash": "qB5urvw9LO2bG3eVAkuL+2ughxz2rR7aYgm2iyrB8Rlk9cp2ndvGRCvehk3rNIhRuNtQaeKwctOl1KvWiklv5w==",
"dependencies": {
"Microsoft.Build.Tasks.Git": "1.1.1",
"Microsoft.SourceLink.Common": "1.1.1"
}
},
"Microsoft.SourceLink.Bitbucket.Git": {
"type": "Transitive",
"resolved": "1.1.1",
"contentHash": "cDzxXwlyWpLWaH0em4Idj0H3AmVo3L/6xRXKssYemx+7W52iNskj/SQ4FOmfCb8YQt39otTDNMveCZzYtMoucQ==",
"dependencies": {
"Microsoft.Build.Tasks.Git": "1.1.1",
"Microsoft.SourceLink.Common": "1.1.1"
}
},
"Microsoft.SourceLink.Common": {
"type": "Transitive",
"resolved": "8.0.0",
"contentHash": "dk9JPxTCIevS75HyEQ0E4OVAFhB2N+V9ShCXf8Q6FkUQZDkgLI12y679Nym1YqsiSysuQskT7Z+6nUf3yab6Vw=="
},
"Microsoft.SourceLink.GitHub": {
"type": "Transitive",
"resolved": "1.1.1",
"contentHash": "IaJGnOv/M7UQjRJks7B6p7pbPnOwisYGOIzqCz5ilGFTApZ3ktOR+6zJ12ZRPInulBmdAf1SrGdDG2MU8g6XTw==",
"dependencies": {
"Microsoft.Build.Tasks.Git": "1.1.1",
"Microsoft.SourceLink.Common": "1.1.1"
}
},
"Microsoft.SourceLink.GitLab": {
"type": "Transitive",
"resolved": "1.1.1",
"contentHash": "tvsg47DDLqqedlPeYVE2lmiTpND8F0hkrealQ5hYltSmvruy/Gr5nHAKSsjyw5L3NeM/HLMI5ORv7on/M4qyZw==",
"dependencies": {
"Microsoft.Build.Tasks.Git": "1.1.1",
"Microsoft.SourceLink.Common": "1.1.1"
}
},
"llib": {
"type": "Project",
"dependencies": {
"DalamudPackager": "[2.1.13, )"
}
}
}
}
}

View File

@ -1,21 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Dalamud.NET.Sdk/9.0.2">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject> <IsTestProject>true</IsTestProject>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <Import Project="..\LLib\LLib.targets"/>
<DalamudLibPath>$(appdata)\XIVLauncher\addon\Hooks\dev\</DalamudLibPath>
</PropertyGroup>
<PropertyGroup Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))'">
<DalamudLibPath>$(DALAMUD_HOME)/</DalamudLibPath>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0"/> <PackageReference Include="coverlet.collector" Version="6.0.0"/>
@ -24,24 +13,14 @@
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3"/> <PackageReference Include="xunit.runner.visualstudio" Version="2.5.3"/>
</ItemGroup> </ItemGroup>
<!-- Need to be explicitly added for test projects, as it otherwise won't find the DLLs -->
<ItemGroup> <ItemGroup>
<Reference Include="Dalamud"> <Reference Include="Dalamud"/>
<HintPath>$(DalamudLibPath)Dalamud.dll</HintPath> <Reference Include="Lumina"/>
</Reference> <Reference Include="Lumina.Excel"/>
<Reference Include="Lumina">
<HintPath>$(DalamudLibPath)Lumina.dll</HintPath>
</Reference>
<Reference Include="Lumina.Excel">
<HintPath>$(DalamudLibPath)Lumina.Excel.dll</HintPath>
</Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Gearsetter\Gearsetter.csproj"/> <ProjectReference Include="..\Gearsetter\Gearsetter.csproj"/>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Using Include="Xunit"/>
</ItemGroup>
</Project> </Project>

View File

@ -0,0 +1,6 @@
{
"Name": "Gearsetter.Test",
"Author": "Liza Carvelli",
"Punchline": "",
"Description": ""
}

View File

@ -1,12 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Gearsetter.GameData; using Gearsetter.GameData;
using Gearsetter.Model; using Gearsetter.Model;
using LLib.GameData;
using Lumina.Excel.GeneratedSheets; using Lumina.Excel.GeneratedSheets;
using Xunit;
namespace Gearsetter.Test; namespace Gearsetter.Test;
public sealed class ItemSortingTest public sealed class ItemSortingTest
{ {
Lumina.GameData _lumina = new( "C:/Program Files (x86)/steam/steamapps/common/FINAL FANTASY XIV Online/game/sqpack" ); Lumina.GameData _lumina = new("C:/Program Files (x86)/steam/steamapps/common/FINAL FANTASY XIV Online/game/sqpack");
[Fact] [Fact]
public void Test1() public void Test1()
@ -33,7 +38,6 @@ public sealed class ItemSortingTest
Items = initialItemIds.Select(rowId => new EquipmentItem(items.GetRow(rowId)!, false)) Items = initialItemIds.Select(rowId => new EquipmentItem(items.GetRow(rowId)!, false))
.Cast<BaseItem>() .Cast<BaseItem>()
.ToList(), .ToList(),
}; };
var primaryStats = _lumina.GetExcelSheet<ClassJob>()! var primaryStats = _lumina.GetExcelSheet<ClassJob>()!

File diff suppressed because it is too large Load Diff

View File

@ -4,6 +4,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gearsetter", "Gearsetter\Ge
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gearsetter.Test", "Gearsetter.Test\Gearsetter.Test.csproj", "{19044F87-4C6D-4926-B5C8-5BB7760DC44C}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gearsetter.Test", "Gearsetter.Test\Gearsetter.Test.csproj", "{19044F87-4C6D-4926-B5C8-5BB7760DC44C}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LLib", "LLib\LLib.csproj", "{66144F9D-AC38-4F16-B269-A610F8EB7A3F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gearsetter.IpcTest", "Gearsetter.IpcTest\Gearsetter.IpcTest.csproj", "{D5BFA879-0A33-4640-B75E-D92D8F23D6F1}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -18,5 +22,13 @@ Global
{19044F87-4C6D-4926-B5C8-5BB7760DC44C}.Debug|Any CPU.Build.0 = Debug|Any CPU {19044F87-4C6D-4926-B5C8-5BB7760DC44C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{19044F87-4C6D-4926-B5C8-5BB7760DC44C}.Release|Any CPU.ActiveCfg = Release|Any CPU {19044F87-4C6D-4926-B5C8-5BB7760DC44C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{19044F87-4C6D-4926-B5C8-5BB7760DC44C}.Release|Any CPU.Build.0 = Release|Any CPU {19044F87-4C6D-4926-B5C8-5BB7760DC44C}.Release|Any CPU.Build.0 = Release|Any CPU
{66144F9D-AC38-4F16-B269-A610F8EB7A3F}.Debug|Any CPU.ActiveCfg = Debug|x64
{66144F9D-AC38-4F16-B269-A610F8EB7A3F}.Debug|Any CPU.Build.0 = Debug|x64
{66144F9D-AC38-4F16-B269-A610F8EB7A3F}.Release|Any CPU.ActiveCfg = Debug|x64
{66144F9D-AC38-4F16-B269-A610F8EB7A3F}.Release|Any CPU.Build.0 = Debug|x64
{D5BFA879-0A33-4640-B75E-D92D8F23D6F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D5BFA879-0A33-4640-B75E-D92D8F23D6F1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D5BFA879-0A33-4640-B75E-D92D8F23D6F1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D5BFA879-0A33-4640-B75E-D92D8F23D6F1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

64
Gearsetter/External/GearsetterIpc.cs vendored Normal file
View File

@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Dalamud.Plugin;
using Dalamud.Plugin.Ipc;
using Dalamud.Plugin.Services;
using FFXIVClientStructs.FFXIV.Client.Game;
using FFXIVClientStructs.FFXIV.Client.UI.Misc;
namespace Gearsetter.External;
internal sealed class GearsetterIpc : IDisposable
{
private const string IpcGetRecommendationsForGearset = "Gearsetter.GetRecommendationsForGearset";
private readonly GearsetterPlugin _plugin;
private readonly IPluginLog _pluginLog;
private readonly ICallGateProvider<byte,
List<(uint ItemId, InventoryType? SourceInventory, int? SourceInventorySlot,
RaptureGearsetModule.GearsetItemIndex TargetSlot)>>
_getRecommendationsForGearset;
public GearsetterIpc(GearsetterPlugin plugin, IDalamudPluginInterface pluginInterface, IPluginLog pluginLog)
{
_plugin = plugin;
_pluginLog = pluginLog;
_getRecommendationsForGearset =
pluginInterface
.GetIpcProvider<byte,
List<(uint, InventoryType?, int?, RaptureGearsetModule.GearsetItemIndex TargetSlot)>>(
IpcGetRecommendationsForGearset);
_getRecommendationsForGearset.RegisterFunc(GetRecommendationsForGearset);
}
private unsafe List<(uint ItemId, InventoryType? SourceInventory, int? SourceInventorySlot,
RaptureGearsetModule.GearsetItemIndex TargetSlot)>
GetRecommendationsForGearset(byte gearsetId)
{
if (gearsetId > 100)
throw new ArgumentOutOfRangeException(nameof(gearsetId));
var gearsetModule = RaptureGearsetModule.Instance();
if (gearsetModule == null)
throw new InvalidOperationException($"{nameof(RaptureGearsetModule)} is null");
var gearset = gearsetModule->GetGearset(gearsetId);
if (gearset == null)
throw new InvalidOperationException($"Gearset {gearsetId} is null");
if (!gearset->Flags.HasFlag(RaptureGearsetModule.GearsetFlag.Exists))
throw new InvalidOperationException($"Gearset {gearsetId} does not exist");
_pluginLog.Verbose($"Checking for gearset upgrades for gearset {gearset->Id}.");
return _plugin.GetRecommendedUpgrades(gearset)
.Select(x => (x.ItemId, x.SourceInventory, x.SourceInventorySlot, x.TargetSlot))
.ToList();
}
public void Dispose()
{
_getRecommendationsForGearset.UnregisterFunc();
}
}

View File

@ -1,113 +0,0 @@
namespace Gearsetter.GameData;
internal enum EClassJob : uint
{
Adventurer = 0,
Gladiator = 1,
Pugilist = 2,
Marauder = 3,
Lancer = 4,
Archer = 5,
Conjurer = 6,
Thaumaturge = 7,
Carpenter = 8,
Blacksmith = 9,
Armorer = 10,
Goldsmith = 11,
Leatherworker = 12,
Weaver = 13,
Alchemist = 14,
Culinarian = 15,
Miner = 16,
Botanist = 17,
Fisher = 18,
Paladin = 19,
Monk = 20,
Warrior = 21,
Dragoon = 22,
Bard = 23,
WhiteMage = 24,
BlackMage = 25,
Arcanist = 26,
Summoner = 27,
Scholar = 28,
Rogue = 29,
Ninja = 30,
Machinist = 31,
DarkKnight = 32,
Astrologian = 33,
Samurai = 34,
RedMage = 35,
BlueMage = 36,
Gunbreaker = 37,
Dancer = 38,
Reaper = 39,
Sage = 40,
}
internal static class EClassJobExtensions
{
public static EClassJob AsJob(this EClassJob classJob) => classJob switch
{
EClassJob.Gladiator => EClassJob.Paladin,
EClassJob.Marauder => EClassJob.Warrior,
EClassJob.Pugilist => EClassJob.Monk,
EClassJob.Lancer => EClassJob.Dragoon,
EClassJob.Rogue => EClassJob.Ninja,
EClassJob.Archer => EClassJob.Bard,
EClassJob.Conjurer => EClassJob.WhiteMage,
EClassJob.Thaumaturge => EClassJob.BlackMage,
EClassJob.Arcanist => EClassJob.Summoner,
_ => classJob,
};
public static bool IsTank(this EClassJob classJob) =>
classJob is EClassJob.Gladiator
or EClassJob.Paladin
or EClassJob.Marauder
or EClassJob.Warrior
or EClassJob.DarkKnight
or EClassJob.Gunbreaker;
public static bool IsHealer(this EClassJob classJob) =>
classJob is EClassJob.Conjurer
or EClassJob.WhiteMage
or EClassJob.Scholar
or EClassJob.Astrologian
or EClassJob.Sage;
public static bool IsMelee(this EClassJob classJob) =>
classJob is EClassJob.Pugilist
or EClassJob.Monk
or EClassJob.Lancer
or EClassJob.Dragoon
or EClassJob.Rogue
or EClassJob.Ninja
or EClassJob.Samurai
or EClassJob.Reaper;
public static bool IsPhysicalRanged(this EClassJob classJob) =>
classJob is EClassJob.Archer
or EClassJob.Bard
or EClassJob.Machinist
or EClassJob.Dancer;
public static bool IsCaster(this EClassJob classJob) =>
classJob is EClassJob.Thaumaturge
or EClassJob.BlackMage
or EClassJob.Arcanist
or EClassJob.Summoner
or EClassJob.RedMage
or EClassJob.BlueMage;
public static bool DealsPhysicalDamage(this EClassJob classJob) =>
classJob.IsTank() || classJob.IsMelee() || classJob.IsPhysicalRanged();
public static bool DealsMagicDamage(this EClassJob classJob) =>
classJob.IsHealer() || classJob.IsCaster();
public static bool IsCrafter(this EClassJob classJob) =>
classJob is >= EClassJob.Carpenter and <= EClassJob.Culinarian;
public static bool IsGatherer(this EClassJob classJob) => classJob is >= EClassJob.Miner and <= EClassJob.Fisher;
}

View File

@ -2,9 +2,11 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Dalamud; using Dalamud;
using Dalamud.Game;
using Dalamud.Plugin.Services; using Dalamud.Plugin.Services;
using FFXIVClientStructs.FFXIV.Client.Game; using FFXIVClientStructs.FFXIV.Client.Game;
using Gearsetter.Model; using Gearsetter.Model;
using LLib.GameData;
using Lumina.Excel.GeneratedSheets; using Lumina.Excel.GeneratedSheets;
namespace Gearsetter.GameData; namespace Gearsetter.GameData;
@ -63,6 +65,8 @@ internal sealed class GameDataHolder
{ EClassJob.Dancer, x.DNC }, { EClassJob.Dancer, x.DNC },
{ EClassJob.Reaper, x.RPR }, { EClassJob.Reaper, x.RPR },
{ EClassJob.Sage, x.SGE }, { EClassJob.Sage, x.SGE },
{ EClassJob.Viper, x.VPR },
{ EClassJob.Pictomancer, x.PCT }
} }
.Where(y => y.Value) .Where(y => y.Value)
.Select(y => y.Key) .Select(y => y.Key)

View File

@ -1,60 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Dalamud.NET.Sdk/9.0.2">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework> <Version>1.3</Version>
<Version>0.7</Version>
<LangVersion>12</LangVersion>
<Nullable>enable</Nullable>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<OutputPath>dist</OutputPath> <OutputPath>dist</OutputPath>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DebugType>portable</DebugType>
<PathMap Condition="$(SolutionDir) != ''">$(SolutionDir)=X:\</PathMap>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
<DebugType>portable</DebugType>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <Import Project="..\LLib\LLib.targets"/>
<DalamudLibPath>$(appdata)\XIVLauncher\addon\Hooks\dev\</DalamudLibPath> <Import Project="..\LLib\RenameZip.targets"/>
</PropertyGroup>
<PropertyGroup Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))'">
<DalamudLibPath>$(DALAMUD_HOME)/</DalamudLibPath>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="DalamudPackager" Version="2.1.12"/> <ProjectReference Include="..\LLib\LLib.csproj"/>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Reference Include="Dalamud">
<HintPath>$(DalamudLibPath)Dalamud.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="ImGui.NET">
<HintPath>$(DalamudLibPath)ImGui.NET.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="Lumina">
<HintPath>$(DalamudLibPath)Lumina.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="Lumina.Excel">
<HintPath>$(DalamudLibPath)Lumina.Excel.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>$(DalamudLibPath)Newtonsoft.Json.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="FFXIVClientStructs">
<HintPath>$(DalamudLibPath)FFXIVClientStructs.dll</HintPath>
<Private>false</Private>
</Reference>
</ItemGroup>
<Target Name="RenameLatestZip" AfterTargets="PackagePlugin" Condition="'$(Configuration)' == 'Release'">
<Exec Command="rename $(OutDir)$(AssemblyName)\latest.zip $(AssemblyName)-$(Version).zip"/>
</Target>
</Project> </Project>

View File

@ -2,7 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using System.Text; using System.Threading.Tasks;
using Dalamud.Game.Command; using Dalamud.Game.Command;
using Dalamud.Game.Text.SeStringHandling; using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Game.Text.SeStringHandling.Payloads; using Dalamud.Game.Text.SeStringHandling.Payloads;
@ -12,9 +12,11 @@ using Dalamud.Plugin.Services;
using FFXIVClientStructs.FFXIV.Client.Game; using FFXIVClientStructs.FFXIV.Client.Game;
using FFXIVClientStructs.FFXIV.Client.Game.UI; using FFXIVClientStructs.FFXIV.Client.Game.UI;
using FFXIVClientStructs.FFXIV.Client.UI.Misc; using FFXIVClientStructs.FFXIV.Client.UI.Misc;
using Gearsetter.External;
using Gearsetter.GameData; using Gearsetter.GameData;
using Gearsetter.Model; using Gearsetter.Model;
using Gearsetter.Windows; using Gearsetter.Windows;
using LLib.GameData;
using Lumina.Excel.GeneratedSheets; using Lumina.Excel.GeneratedSheets;
using GrandCompany = FFXIVClientStructs.FFXIV.Client.UI.Agent.GrandCompany; using GrandCompany = FFXIVClientStructs.FFXIV.Client.UI.Agent.GrandCompany;
using InventoryItem = FFXIVClientStructs.FFXIV.Client.Game.InventoryItem; using InventoryItem = FFXIVClientStructs.FFXIV.Client.Game.InventoryItem;
@ -25,21 +27,21 @@ namespace Gearsetter;
public sealed class GearsetterPlugin : IDalamudPlugin public sealed class GearsetterPlugin : IDalamudPlugin
{ {
private readonly WindowSystem _windowSystem = new(nameof(GearsetterPlugin)); private readonly WindowSystem _windowSystem = new(nameof(GearsetterPlugin));
private readonly DalamudPluginInterface _pluginInterface; private readonly IDalamudPluginInterface _pluginInterface;
private readonly ICommandManager _commandManager; private readonly ICommandManager _commandManager;
private readonly IChatGui _chatGui; private readonly IChatGui _chatGui;
private readonly IDataManager _dataManager; private readonly IDataManager _dataManager;
private readonly IPluginLog _pluginLog; private readonly IPluginLog _pluginLog;
private readonly IClientState _clientState; private readonly IClientState _clientState;
private readonly GearsetterIpc _gearsetterIpc;
private readonly Configuration _configuration; private readonly Configuration _configuration;
private readonly GameDataHolder _gameDataHolder; private readonly GameDataHolder _gameDataHolder;
private readonly EquipmentBrowserWindow _equipmentBrowserWindow; private readonly EquipmentBrowserWindow _equipmentBrowserWindow;
private readonly ConfigWindow _configWindow; private readonly ConfigWindow _configWindow;
private readonly IReadOnlyDictionary<byte, DalamudLinkPayload> _linkPayloads; private readonly IReadOnlyDictionary<byte, DalamudLinkPayload> _linkPayloads;
private readonly Dictionary<EClassJob, byte> _classJobToArrayIndex; private readonly Dictionary<EClassJob, byte> _classJobToArrayIndex;
public GearsetterPlugin(DalamudPluginInterface pluginInterface, ICommandManager commandManager, IChatGui chatGui, public GearsetterPlugin(IDalamudPluginInterface pluginInterface, ICommandManager commandManager, IChatGui chatGui,
IDataManager dataManager, IPluginLog pluginLog, IClientState clientState) IDataManager dataManager, IPluginLog pluginLog, IClientState clientState)
{ {
ArgumentNullException.ThrowIfNull(dataManager); ArgumentNullException.ThrowIfNull(dataManager);
@ -50,6 +52,7 @@ public sealed class GearsetterPlugin : IDalamudPlugin
_dataManager = dataManager; _dataManager = dataManager;
_pluginLog = pluginLog; _pluginLog = pluginLog;
_clientState = clientState; _clientState = clientState;
_gearsetterIpc = new GearsetterIpc(this, _pluginInterface, _pluginLog);
Configuration? configuration = (Configuration?)_pluginInterface.GetPluginConfig(); Configuration? configuration = (Configuration?)_pluginInterface.GetPluginConfig();
if (configuration == null) if (configuration == null)
@ -122,6 +125,7 @@ public sealed class GearsetterPlugin : IDalamudPlugin
private unsafe void ShowUpgrades(byte? level = null) private unsafe void ShowUpgrades(byte? level = null)
{ {
DateTime start = DateTime.Now;
var inventoryItems = GetAllInventoryItems(); var inventoryItems = GetAllInventoryItems();
var gearsetModule = RaptureGearsetModule.Instance(); var gearsetModule = RaptureGearsetModule.Instance();
@ -132,7 +136,7 @@ public sealed class GearsetterPlugin : IDalamudPlugin
if (onlyCurrentJob) if (onlyCurrentJob)
_chatGui.Print("Checking only gearsets for your current class/job..."); _chatGui.Print("Checking only gearsets for your current class/job...");
bool anyUpgrade = false; List<GearsetData> gearsets = new List<GearsetData>();
for (int i = 0; i < 100; ++i) for (int i = 0; i < 100; ++i)
{ {
var gearset = gearsetModule->GetGearset(i); var gearset = gearsetModule->GetGearset(i);
@ -141,64 +145,106 @@ public sealed class GearsetterPlugin : IDalamudPlugin
if (onlyCurrentJob && gearset->ClassJob != _clientState.LocalPlayer!.ClassJob.Id) if (onlyCurrentJob && gearset->ClassJob != _clientState.LocalPlayer!.ClassJob.Id)
continue; continue;
var gearsetData = PrepareGearset(gearset);
if (gearsetData != null)
gearsets.Add(gearsetData);
}
}
_pluginLog.Information($"Preparing gearsets took {DateTime.Now - start}");
Task.Run(() =>
{
start = DateTime.Now;
bool anyUpgrade = false;
foreach (GearsetData gearset in gearsets)
anyUpgrade |= HandleGearset(gearset, inventoryItems, level); anyUpgrade |= HandleGearset(gearset, inventoryItems, level);
}
}
if (!anyUpgrade) if (!anyUpgrade)
_chatGui.Print("All your gearsets are OK."); _chatGui.Print("All your gearsets are OK.");
_pluginLog.Information($"Evaluating gearsets took {DateTime.Now - start}");
});
} }
private unsafe bool HandleGearset(RaptureGearsetModule.GearsetEntry* gearset, private unsafe GearsetData? PrepareGearset(RaptureGearsetModule.GearsetEntry* gearset)
Dictionary<(uint ItemId, bool Hq), List<MateriaStats>> inventoryItems, byte? level)
{ {
string name = GetGearsetName(gearset); string name = GetGearsetName(gearset);
if (name.Contains('_', StringComparison.Ordinal) || if (name.Contains('_', StringComparison.Ordinal) ||
name.Contains("Eureka", StringComparison.OrdinalIgnoreCase) || name.Contains("Eureka", StringComparison.OrdinalIgnoreCase) ||
name.Contains("Bozja", StringComparison.OrdinalIgnoreCase)) name.Contains("Bozja", StringComparison.OrdinalIgnoreCase))
return false; return null;
List<SeString> Handle(string label, int[] spanIds, EEquipSlotCategory category) return new GearsetData(_dataManager, gearset, name);
{
return HandleGearsetItem(label, gearset, spanIds.Select(x => gearset->ItemsSpan[x]).ToArray(),
inventoryItems, category, level);
} }
List<List<SeString>> upgrades = new() internal unsafe List<RecommendedItemChange> GetRecommendedUpgrades(RaptureGearsetModule.GearsetEntry* gearset,
byte? level = null)
{ {
Handle("Main Hand", [0], EEquipSlotCategory.None), GearsetData gearsetData = new GearsetData(_dataManager, gearset, GetGearsetName(gearset));
Dictionary<(uint ItemId, bool Hq), List<MateriaStats>> inventoryItems = GetAllInventoryItems();
return GetRecommendedUpgrades(gearsetData, inventoryItems, level);
}
private List<RecommendedItemChange> GetRecommendedUpgrades(GearsetData gearset,
Dictionary<(uint ItemId, bool Hql), List<MateriaStats>> inventoryItems, byte? level)
{
List<RecommendedItemChange> Handle(string label,
(EquipmentItem?, RaptureGearsetModule.GearsetItemIndex)[] gearsetItems,
EEquipSlotCategory category)
{
return HandleGearsetItem(label, gearset, gearsetItems, inventoryItems, category, level);
}
List<List<RecommendedItemChange>> upgrades = new()
{
Handle("Main Hand", [(gearset.MainHand, RaptureGearsetModule.GearsetItemIndex.MainHand)],
EEquipSlotCategory.None),
HandleOffHand(gearset, inventoryItems, level), HandleOffHand(gearset, inventoryItems, level),
Handle("Head", [2], EEquipSlotCategory.Head), Handle("Head", [(gearset.Head, RaptureGearsetModule.GearsetItemIndex.Head)], EEquipSlotCategory.Head),
Handle("Body", [3], EEquipSlotCategory.Body), Handle("Body", [(gearset.Body, RaptureGearsetModule.GearsetItemIndex.Body)], EEquipSlotCategory.Body),
Handle("Hands", [4], EEquipSlotCategory.Hands), Handle("Hands", [(gearset.Hands, RaptureGearsetModule.GearsetItemIndex.Hands)], EEquipSlotCategory.Hands),
Handle("Legs", [6], EEquipSlotCategory.Legs), Handle("Legs", [(gearset.Legs, RaptureGearsetModule.GearsetItemIndex.Legs)], EEquipSlotCategory.Legs),
Handle("Feet", [7], EEquipSlotCategory.Feet), Handle("Feet", [(gearset.Feet, RaptureGearsetModule.GearsetItemIndex.Feet)], EEquipSlotCategory.Feet),
Handle("Ears", [8], EEquipSlotCategory.Ears), Handle("Ears", [(gearset.Ears, RaptureGearsetModule.GearsetItemIndex.Ears)], EEquipSlotCategory.Ears),
Handle("Neck", [9], EEquipSlotCategory.Neck), Handle("Neck", [(gearset.Neck, RaptureGearsetModule.GearsetItemIndex.Neck)], EEquipSlotCategory.Neck),
Handle("Wrists", [10], EEquipSlotCategory.Wrists), Handle("Wrists", [(gearset.Wrists, RaptureGearsetModule.GearsetItemIndex.Wrists)],
Handle("Rings", [11, 12], EEquipSlotCategory.Rings), EEquipSlotCategory.Wrists),
Handle("Rings",
[
(gearset.RingLeft, RaptureGearsetModule.GearsetItemIndex.RingLeft),
(gearset.RingRight, RaptureGearsetModule.GearsetItemIndex.RingRight)
],
EEquipSlotCategory.Rings),
}; };
List<SeString> flatUpgrades = upgrades.SelectMany(x => x).ToList(); return upgrades.SelectMany(x => x).ToList();
if (flatUpgrades.Count == 0) }
private bool HandleGearset(GearsetData gearset,
Dictionary<(uint ItemId, bool Hq), List<MateriaStats>> inventoryItems, byte? level)
{
List<RecommendedItemChange> upgrades = GetRecommendedUpgrades(gearset, inventoryItems, level);
if (upgrades.Count == 0)
return false; return false;
_chatGui.Print( _chatGui.Print(
new SeStringBuilder() new SeStringBuilder()
.Append("Gearset ") .Append("Gearset ")
.AddUiForeground(1) .AddUiForeground(1)
.Add(_linkPayloads[gearset->ID]) .Add(_linkPayloads[gearset.Id])
.Append($"#{gearset->ID + 1}: ") .Append($"#{gearset.Id + 1}: ")
.Append(name) .Append(gearset.Name)
.Add(RawPayload.LinkTerminator) .Add(RawPayload.LinkTerminator)
.AddUiForegroundOff() .AddUiForegroundOff()
.AddText(level != null ? $" at {level}" : "") .AddText(level != null ? $" at {level}" : "")
.Build()); .Build());
foreach (var upgrade in flatUpgrades) foreach (var upgrade in upgrades)
_chatGui.Print(new SeString(new TextPayload(" - ")).Append(upgrade)); _chatGui.Print(new SeString(new TextPayload(" - ")).Append(upgrade.Text));
return true; return true;
} }
@ -208,49 +254,45 @@ public sealed class GearsetterPlugin : IDalamudPlugin
/// the string ends after the name (and not render ANY text on the same line after the name). /// the string ends after the name (and not render ANY text on the same line after the name).
/// </summary> /// </summary>
private unsafe string GetGearsetName(RaptureGearsetModule.GearsetEntry* gearset) private unsafe string GetGearsetName(RaptureGearsetModule.GearsetEntry* gearset)
=> Encoding.UTF8.GetString(gearset->Name, 0x2F).Split((char)0)[0]; => gearset->NameString.Split((char)0)[0];
private unsafe List<SeString> HandleGearsetItem(string label, RaptureGearsetModule.GearsetEntry* gearset, private List<RecommendedItemChange> HandleGearsetItem(string label, GearsetData gearset,
RaptureGearsetModule.GearsetItem[] gearsetItem, (EquipmentItem? Item, RaptureGearsetModule.GearsetItemIndex Slot)[] gearsetItems,
Dictionary<(uint ItemId, bool Hq), List<MateriaStats>> inventoryItems, Dictionary<(uint ItemId, bool Hq), List<MateriaStats>> inventoryItems,
EEquipSlotCategory equipSlotCategory, byte? level) EEquipSlotCategory equipSlotCategory, byte? level)
{ {
EClassJob classJob = (EClassJob)gearset->ClassJob; EClassJob classJob = gearset.ClassJob;
List<RaptureGearsetModule.GearsetItemIndex> availableGearsetSlots = gearsetItems.Select(x => x.Slot).ToList();
var itemLists = _gameDataHolder.GetItemLists(classJob); var itemLists = _gameDataHolder.GetItemLists(classJob);
if (gearsetItem.Any(x => x.ItemID > 0)) if (equipSlotCategory == EEquipSlotCategory.None && gearsetItems.Any(x => x.Item != null))
{ {
var firstEquippedItem = gearsetItem.First(x => x.ItemID > 0); var firstEquippedItem = gearsetItems.First(x => x.Item != null);
equipSlotCategory = (EEquipSlotCategory)(_dataManager.GetExcelSheet<Item>()! equipSlotCategory = firstEquippedItem.Item!.EquipSlotCategory;
.GetRow(firstEquippedItem.ItemID % 1_000_000)
?.EquipSlotCategory?.Row ?? 0);
} }
if (equipSlotCategory == EEquipSlotCategory.None) if (equipSlotCategory == EEquipSlotCategory.None)
{ {
_pluginLog.Warning($"Unable to find item to determine equip slot category"); _pluginLog.Warning("Unable to find item to determine equip slot category");
return new List<SeString>(); return [];
} }
BaseItem?[] currentItems = gearsetItem.Select(x => new (BaseItem? Item, RaptureGearsetModule.GearsetItemIndex Slot)[] currentItems = gearsetItems
{
ItemId = x.ItemID % 1_000_000,
Hq = x.ItemID > 1_000_000
})
.Select(x => .Select(x =>
{ {
if (x.ItemId == 0) if (x.Item == null)
return null; return (null, x.Slot);
return itemLists var baseItem = itemLists
.SelectMany(y => y.Items.Where(z => x.ItemId == z.ItemId && x.Hq == z.Hq)) .SelectMany(y => y.Items.Where(z => x.Item.ItemId == z.ItemId && x.Item.Hq == z.Hq))
.FirstOrDefault(); .FirstOrDefault();
return (baseItem, x.Slot);
}) })
.ToArray(); .ToArray();
var availableList = _gameDataHolder.GetItemList(classJob, equipSlotCategory); var availableList = _gameDataHolder.GetItemList(classJob, equipSlotCategory);
if (availableList == null) if (availableList == null)
return new List<SeString>(); return [];
if (level == null) if (level == null)
level = GetLevel(classJob); level = GetLevel(classJob);
@ -262,21 +304,32 @@ public sealed class GearsetterPlugin : IDalamudPlugin
var bestItems = availableList.Items var bestItems = availableList.Items
.Where(x => x.Level <= level) .Where(x => x.Level <= level)
.Where(x => x is Model.InventoryItem) .Where(x => x is Model.InventoryItem)
.Take(gearsetItem.Length) .Take(gearsetItems.Length)
.ToList(); .ToList();
_pluginLog.Debug( //_pluginLog.Debug(
$"{equipSlotCategory}: {string.Join(" ", currentItems.Select(x => $"{x?.ItemId}|{x?.Hq}"))}"); // $"{equipSlotCategory}: {string.Join(" ", currentItems.Select(x => $"{x.Item}, {x.Slot}"))}");
foreach (var currentItem in currentItems) foreach (var currentItem in currentItems)
{ {
var foundIndex = bestItems.FindIndex(x => var foundIndex = bestItems.FindIndex(x =>
currentItem != null && currentItem.ItemId == x.ItemId && currentItem.Hq == x.Hq); currentItem.Item != null && currentItem.Item.ItemId == x.ItemId && currentItem.Item.Hq == x.Hq);
if (foundIndex >= 0) if (foundIndex >= 0)
{
bestItems.RemoveAt(foundIndex); bestItems.RemoveAt(foundIndex);
availableGearsetSlots.Remove(currentItem.Slot);
}
} }
return bestItems return bestItems
.Select(x => new SeString(new TextPayload($"{label}: ")) .Select(x =>
.Append(SeString.CreateItemLink(x.ItemId, x.Hq))).ToList(); {
var slot = availableGearsetSlots[0];
availableGearsetSlots.RemoveAt(0);
return ToItemRecommendation(x, slot,
new SeString(new TextPayload($"{label}: "))
.Append(SeString.CreateItemLink(x.ItemId, x.Hq)));
})
.ToList();
} }
finally finally
{ {
@ -284,27 +337,53 @@ public sealed class GearsetterPlugin : IDalamudPlugin
} }
} }
private List<RecommendedItemChange> HandleOffHand(GearsetData gearset,
private unsafe List<SeString> HandleOffHand(RaptureGearsetModule.GearsetEntry* gearset,
Dictionary<(uint ItemId, bool Hq), List<MateriaStats>> inventoryItems, byte? level) Dictionary<(uint ItemId, bool Hq), List<MateriaStats>> inventoryItems, byte? level)
{ {
var mainHand = gearset->ItemsSpan[0]; var mainHand = gearset.MainHand;
if (mainHand.ItemID == 0) if (mainHand == null)
return new List<SeString>(); return [];
// if it's a twohanded weapon, ignore it // if it's a twohanded weapon, ignore it
EEquipSlotCategory equipSlotCategory = EEquipSlotCategory equipSlotCategory = mainHand.EquipSlotCategory;
(EEquipSlotCategory)(_dataManager.GetExcelSheet<Item>()!.GetRow(mainHand.ItemID % 1_000_000)?.RowId ?? 0);
if (equipSlotCategory != EEquipSlotCategory.OneHandedMainHand) if (equipSlotCategory != EEquipSlotCategory.OneHandedMainHand)
return new List<SeString>(); return [];
return HandleGearsetItem("Off Hand", gearset, [gearset->ItemsSpan[1]], inventoryItems, return HandleGearsetItem("Off Hand", gearset,
[(gearset.OffHand, RaptureGearsetModule.GearsetItemIndex.OffHand)],
inventoryItems,
EEquipSlotCategory.Shield, level); EEquipSlotCategory.Shield, level);
} }
private unsafe void ChangeGearset(uint commandId, SeString seString) private unsafe void ChangeGearset(uint commandId, SeString seString)
=> RaptureGearsetModule.Instance()->EquipGearset((byte)commandId); => RaptureGearsetModule.Instance()->EquipGearset((byte)commandId);
private unsafe RecommendedItemChange ToItemRecommendation(BaseItem baseItem,
RaptureGearsetModule.GearsetItemIndex targetSlot, SeString text)
{
InventoryManager* inventoryManager = InventoryManager.Instance();
foreach (var inventoryType in _gameDataHolder.DefaultInventoryTypes)
{
var container = inventoryManager->GetInventoryContainer(inventoryType);
for (int i = 0; i < container->Size; ++i)
{
var item = container->GetInventorySlot(i);
if (item != null && item->ItemId == baseItem.ItemId &&
item->Flags.HasFlag(InventoryItem.ItemFlags.HighQuality) == baseItem.Hq)
{
MateriaStats expectedMateriaStats = baseItem.MateriaStats ?? new([]);
MateriaStats actualMateriaStats = FetchMateriaStats(item);
if (expectedMateriaStats == actualMateriaStats)
return new RecommendedItemChange(item->ItemId, inventoryType, i, targetSlot, text);
}
}
}
return new RecommendedItemChange(baseItem.ItemId, null, null, targetSlot, text);
}
internal unsafe Dictionary<(uint ItemId, bool Hq), List<MateriaStats>> GetAllInventoryItems() internal unsafe Dictionary<(uint ItemId, bool Hq), List<MateriaStats>> GetAllInventoryItems()
{ {
Dictionary<(uint, bool), List<MateriaStats>> inventoryItems = new(); Dictionary<(uint, bool), List<MateriaStats>> inventoryItems = new();
@ -315,30 +394,16 @@ public sealed class GearsetterPlugin : IDalamudPlugin
for (int i = 0; i < container->Size; ++i) for (int i = 0; i < container->Size; ++i)
{ {
var item = container->GetInventorySlot(i); var item = container->GetInventorySlot(i);
if (item != null && item->ItemID != 0) if (item != null && item->ItemId != 0)
{ {
var key = (item->ItemID, item->Flags.HasFlag(InventoryItem.ItemFlags.HQ)); var key = (item->ItemId, item->Flags.HasFlag(InventoryItem.ItemFlags.HighQuality));
if (!inventoryItems.TryGetValue(key, out var list)) if (!inventoryItems.TryGetValue(key, out var list))
{ {
list = new List<MateriaStats>(); list = new List<MateriaStats>();
inventoryItems[key] = list; inventoryItems[key] = list;
} }
list.Add(FetchMateriaStats(item));
byte materiaCount = item->GetMateriaCount();
var materias = Enumerable.Range(0, materiaCount)
.Select<int, (MateriaStat, byte)?>(slot =>
{
if (_gameDataHolder.Materias.TryGetValue(item->GetMateriaId((byte)slot),
out MateriaStat? value))
return (value, item->GetMateriaGrade((byte)slot));
else
return null;
})
.Where(x => x != null)
.Select(x => x!.Value)
.ToList();
list.Add(new MateriaStats(materias));
} }
} }
} }
@ -346,13 +411,30 @@ public sealed class GearsetterPlugin : IDalamudPlugin
return inventoryItems; return inventoryItems;
} }
private unsafe MateriaStats FetchMateriaStats(InventoryItem* item)
{
// FIXME item->GetMateriaCount is broken on API 10, so this seems to be somewhat slow
List<(MateriaStat, byte)> materias = new();
for (int slot = 0; slot < 5; ++slot)
{
var materiaId = item->Materia[slot];
if (materiaId == 0)
break;
if (_gameDataHolder.Materias.TryGetValue(materiaId, out MateriaStat? value))
materias.Add((value, item->MateriaGrades[slot]));
}
return new MateriaStats(materias);
}
internal unsafe byte GetLevel(EClassJob classJob) internal unsafe byte GetLevel(EClassJob classJob)
{ {
var playerState = PlayerState.Instance(); var playerState = PlayerState.Instance();
if (playerState == null) if (playerState == null)
return 0; return 0;
return (byte)playerState->ClassJobLevelArray[_classJobToArrayIndex[classJob]]; return (byte)playerState->ClassJobLevels[_classJobToArrayIndex[classJob]];
} }
public void Dispose() public void Dispose()
@ -364,5 +446,6 @@ public sealed class GearsetterPlugin : IDalamudPlugin
_pluginInterface.RemoveChatLinkHandler(); _pluginInterface.RemoveChatLinkHandler();
_commandManager.RemoveHandler("/gbrowser"); _commandManager.RemoveHandler("/gbrowser");
_commandManager.RemoveHandler("/gup"); _commandManager.RemoveHandler("/gup");
_gearsetterIpc.Dispose();
} }
} }

View File

@ -1,4 +1,5 @@
using Gearsetter.GameData; using Gearsetter.GameData;
using LLib.GameData;
using Lumina.Excel.GeneratedSheets; using Lumina.Excel.GeneratedSheets;
namespace Gearsetter.Model; namespace Gearsetter.Model;

View File

@ -1,4 +1,5 @@
using Gearsetter.GameData; using Gearsetter.GameData;
using LLib.GameData;
using Lumina.Excel.GeneratedSheets; using Lumina.Excel.GeneratedSheets;
namespace Gearsetter.Model; namespace Gearsetter.Model;

View File

@ -0,0 +1,57 @@
using System.Collections.Generic;
using Dalamud.Plugin.Services;
using FFXIVClientStructs.FFXIV.Client.UI.Misc;
using Gearsetter.GameData;
using LLib.GameData;
using Lumina.Excel.GeneratedSheets;
namespace Gearsetter.Model;
internal sealed class GearsetData
{
public unsafe GearsetData(IDataManager dataManager, RaptureGearsetModule.GearsetEntry* gearset, string name)
{
Id = gearset->Id;
ClassJob = (EClassJob)gearset->ClassJob;
Name = name;
MainHand = GetItem(dataManager, gearset, RaptureGearsetModule.GearsetItemIndex.MainHand);
OffHand = GetItem(dataManager, gearset, RaptureGearsetModule.GearsetItemIndex.OffHand);
Head = GetItem(dataManager, gearset, RaptureGearsetModule.GearsetItemIndex.Head);
Body = GetItem(dataManager, gearset, RaptureGearsetModule.GearsetItemIndex.Body);
Hands = GetItem(dataManager, gearset, RaptureGearsetModule.GearsetItemIndex.Hands);
Legs = GetItem(dataManager, gearset, RaptureGearsetModule.GearsetItemIndex.Legs);
Feet = GetItem(dataManager, gearset, RaptureGearsetModule.GearsetItemIndex.Feet);
Ears = GetItem(dataManager, gearset, RaptureGearsetModule.GearsetItemIndex.Ears);
Neck = GetItem(dataManager, gearset, RaptureGearsetModule.GearsetItemIndex.Neck);
Wrists = GetItem(dataManager, gearset, RaptureGearsetModule.GearsetItemIndex.Wrists);
RingLeft = GetItem(dataManager, gearset, RaptureGearsetModule.GearsetItemIndex.RingLeft);
RingRight = GetItem(dataManager, gearset, RaptureGearsetModule.GearsetItemIndex.RingRight);
}
private static unsafe EquipmentItem? GetItem(IDataManager dataManager, RaptureGearsetModule.GearsetEntry* gearset,
RaptureGearsetModule.GearsetItemIndex index)
{
var gearsetItem = gearset->GetItem(index);
if (gearsetItem.ItemId == 0)
return null;
var item = dataManager.GetExcelSheet<Item>()!.GetRow(gearsetItem.ItemId % 1_000_000)!;
return new EquipmentItem(item, gearsetItem.ItemId > 1_000_000);
}
public byte Id { get; }
public EClassJob ClassJob { get; }
public string Name { get; }
public EquipmentItem? MainHand { get; }
public EquipmentItem? OffHand { get; }
public EquipmentItem? Head { get; }
public EquipmentItem? Body { get; }
public EquipmentItem? Hands { get; }
public EquipmentItem? Legs { get; }
public EquipmentItem? Feet { get; }
public EquipmentItem? Ears { get; set; }
public EquipmentItem? Neck { get; set; }
public EquipmentItem? Wrists { get; }
public EquipmentItem? RingLeft { get; }
public EquipmentItem? RingRight { get; }
}

View File

@ -1,4 +1,5 @@
using Gearsetter.GameData; using Gearsetter.GameData;
using LLib.GameData;
using Lumina.Excel.GeneratedSheets; using Lumina.Excel.GeneratedSheets;
namespace Gearsetter.Model; namespace Gearsetter.Model;

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using Gearsetter.GameData; using Gearsetter.GameData;
using LLib.GameData;
namespace Gearsetter.Model; namespace Gearsetter.Model;
@ -10,10 +11,10 @@ internal sealed class ItemList
{ {
private static readonly ReadOnlyDictionary<uint, byte> PreferredItems = new Dictionary<uint, byte>() private static readonly ReadOnlyDictionary<uint, byte> PreferredItems = new Dictionary<uint, byte>()
{ {
{ 41081, 90 }, { 16039, 50 },
{ 33648, 80 },
{ 24589, 70 }, { 24589, 70 },
{ 16039, 50 } { 33648, 80 },
{ 41081, 90 },
}.AsReadOnly(); }.AsReadOnly();
public required EClassJob ClassJob { get; init; } public required EClassJob ClassJob { get; init; }
@ -25,26 +26,9 @@ internal sealed class ItemList
public void Sort() public void Sort()
{ {
var preferredItems = Items Items = Items
.Where(x => PreferredItems.ContainsKey(x.ItemId))
.ToList();
var defaultItems = Items
.Except(preferredItems)
.OrderDescending(new ItemComparer(SubstatPriorities)) .OrderDescending(new ItemComparer(SubstatPriorities))
.ToList(); .ToList();
// insert the preferred items
foreach (BaseItem preferredItem in preferredItems)
{
int level = PreferredItems[preferredItem.ItemId];
int index = defaultItems.FindIndex(x => x.Level < level);
if (index >= 0)
defaultItems.Insert(index, preferredItem);
else
defaultItems.Add(preferredItem);
}
Items = defaultItems;
} }
public void UpdateStats(Dictionary<EClassJob, EBaseParam> primaryStats, Configuration configuration) public void UpdateStats(Dictionary<EClassJob, EBaseParam> primaryStats, Configuration configuration)
@ -120,6 +104,11 @@ internal sealed class ItemList
if (damageA != damageB) if (damageA != damageB)
return damageA.CompareTo(damageB); return damageA.CompareTo(damageB);
bool hasPriorityA = TryGetPreferredItemPriority(a, b, out byte priorityA);
bool hasPriorityB = TryGetPreferredItemPriority(b, a, out byte priorityB);
if ((hasPriorityA || hasPriorityB) && priorityA != priorityB)
return priorityA.CompareTo(priorityB);
// gear: primary stat wins // gear: primary stat wins
// //
// we pretend every gear item has at least 1 primary stat to ensure weathered items are sorted last(ish), // we pretend every gear item has at least 1 primary stat to ensure weathered items are sorted last(ish),
@ -182,5 +171,33 @@ internal sealed class ItemList
// fallback // fallback
return string.CompareOrdinal(a.Name, b.Name); return string.CompareOrdinal(a.Name, b.Name);
} }
public static bool TryGetPreferredItemPriority(BaseItem self, BaseItem other, out byte priority)
{
if (PreferredItems.TryGetValue(self.ItemId, out byte levelSelf))
{
// both items are preferred, sort by level only
if (PreferredItems.TryGetValue(other.ItemId, out byte _))
{
priority = levelSelf;
return true;
}
// if they're the same level, place the preferrd item last
if (levelSelf == other.Level)
{
priority = (byte)(levelSelf - 1);
return true;
}
priority = levelSelf;
return true;
}
else
{
priority = self.Level;
return false;
}
}
} }
} }

View File

@ -5,7 +5,7 @@ using Gearsetter.GameData;
namespace Gearsetter.Model; namespace Gearsetter.Model;
internal sealed class MateriaStats internal sealed class MateriaStats : IEquatable<MateriaStats>
{ {
private readonly List<(EBaseParam, short)> _list; private readonly List<(EBaseParam, short)> _list;
@ -32,18 +32,33 @@ internal sealed class MateriaStats
public override bool Equals(object? obj) public override bool Equals(object? obj)
{ {
if (obj is not MateriaStats other) return ReferenceEquals(this, obj) || obj is MateriaStats other && Equals(other);
return false;
return _list == other._list;
} }
public override int GetHashCode() public override int GetHashCode()
{ {
int hash = 19; return _list.GetHashCode();
hash = hash * 31 + Count; }
foreach (var item in _list)
hash = hash * 31 + item.GetHashCode(); public bool Equals(MateriaStats? other)
return hash; {
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return _list.SequenceEqual(other._list);
}
public static bool operator ==(MateriaStats? left, MateriaStats? right)
{
return Equals(left, right);
}
public static bool operator !=(MateriaStats? left, MateriaStats? right)
{
return !Equals(left, right);
}
public override string ToString()
{
return $"Materias[{string.Join(", ", _list.Select(x => $"{x.Item1}:{x.Item2}"))}]";
} }
} }

View File

@ -0,0 +1,12 @@
using Dalamud.Game.Text.SeStringHandling;
using FFXIVClientStructs.FFXIV.Client.Game;
using FFXIVClientStructs.FFXIV.Client.UI.Misc;
namespace Gearsetter.Model;
internal sealed record RecommendedItemChange(
uint ItemId,
InventoryType? SourceInventory,
int? SourceInventorySlot,
RaptureGearsetModule.GearsetItemIndex TargetSlot,
SeString Text);

View File

@ -1,15 +1,15 @@
using Dalamud.Interface.Windowing; using Dalamud.Plugin;
using Dalamud.Plugin;
using ImGuiNET; using ImGuiNET;
using LLib.ImGui;
namespace Gearsetter.Windows; namespace Gearsetter.Windows;
internal sealed class ConfigWindow : Window internal sealed class ConfigWindow : LWindow
{ {
private readonly DalamudPluginInterface _pluginInterface; private readonly IDalamudPluginInterface _pluginInterface;
private readonly Configuration _configuration; private readonly Configuration _configuration;
public ConfigWindow(DalamudPluginInterface pluginInterface, Configuration configuration) public ConfigWindow(IDalamudPluginInterface pluginInterface, Configuration configuration)
: base("Gearsetter - Config###GearsetterConfig", ImGuiWindowFlags.AlwaysAutoResize) : base("Gearsetter - Config###GearsetterConfig", ImGuiWindowFlags.AlwaysAutoResize)
{ {
_pluginInterface = pluginInterface; _pluginInterface = pluginInterface;

View File

@ -6,15 +6,16 @@ using System.Numerics;
using Dalamud.Game.Text; using Dalamud.Game.Text;
using Dalamud.Game.Text.SeStringHandling; using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Interface.Colors; using Dalamud.Interface.Colors;
using Dalamud.Interface.Windowing;
using Dalamud.Plugin.Services; using Dalamud.Plugin.Services;
using Gearsetter.GameData; using Gearsetter.GameData;
using Gearsetter.Model; using Gearsetter.Model;
using ImGuiNET; using ImGuiNET;
using LLib.GameData;
using LLib.ImGui;
namespace Gearsetter.Windows; namespace Gearsetter.Windows;
internal sealed class EquipmentBrowserWindow : Window internal sealed class EquipmentBrowserWindow : LWindow
{ {
private readonly GearsetterPlugin _plugin; private readonly GearsetterPlugin _plugin;
private readonly GameDataHolder _dataHolder; private readonly GameDataHolder _dataHolder;
@ -71,7 +72,7 @@ internal sealed class EquipmentBrowserWindow : Window
return _clientState.IsLoggedIn; return _clientState.IsLoggedIn;
} }
public override void Draw() public override unsafe void Draw()
{ {
int currentClassJob = Array.IndexOf(_classJobIds, _selectedClassJob); int currentClassJob = Array.IndexOf(_classJobIds, _selectedClassJob);
if (currentClassJob == -1) if (currentClassJob == -1)
@ -124,6 +125,10 @@ internal sealed class EquipmentBrowserWindow : Window
or EEquipSlotCategory.TwoHandedMainHand or EEquipSlotCategory.TwoHandedMainHand
&& !itemList.ClassJob.IsCrafter() && !itemList.ClassJob.IsCrafter()
&& !itemList.ClassJob.IsGatherer(); && !itemList.ClassJob.IsGatherer();
var hoverColorPtr = ImGui.GetStyleColorVec4(ImGuiCol.HeaderHovered);
var hoverColor = new Vector4(hoverColorPtr->X, hoverColorPtr->Y, hoverColorPtr->Z, 0.3f);
if (ImGui.BeginTable("ItemList", 2 + (includeDamage ? 1 : 0) + itemList.SubstatPriorities.Count, if (ImGui.BeginTable("ItemList", 2 + (includeDamage ? 1 : 0) + itemList.SubstatPriorities.Count,
ImGuiTableFlags.Borders | ImGuiTableFlags.Resizable)) ImGuiTableFlags.Borders | ImGuiTableFlags.Resizable))
{ {
@ -132,11 +137,14 @@ internal sealed class EquipmentBrowserWindow : Window
if (includeDamage) if (includeDamage)
ImGui.TableSetupColumn("Damage", ImGuiTableColumnFlags.WidthFixed, 50); ImGui.TableSetupColumn("Damage", ImGuiTableColumnFlags.WidthFixed, 50);
foreach (var substat in itemList.SubstatPriorities) foreach (var substat in itemList.SubstatPriorities)
ImGui.TableSetupColumn(_dataHolder.StatNames[substat], ImGuiTableColumnFlags.WidthFixed, 50); ImGui.TableSetupColumn(_dataHolder.StatNames.GetValueOrDefault(substat, substat.ToString()),
ImGuiTableColumnFlags.WidthFixed, 50);
ImGui.TableHeadersRow(); ImGui.TableHeadersRow();
foreach (var item in itemList.Items.DistinctBy(x => new { x.ItemId, x.Hq, Materia = x.MateriaStats?.GetHashCode() })) ImGui.PushStyleColor(ImGuiCol.HeaderHovered, hoverColor);
foreach (var item in itemList.Items.DistinctBy(x => new
{ x.ItemId, x.Hq, Materia = x.MateriaStats?.GetHashCode() }))
{ {
if (item is not InventoryItem) if (item is not InventoryItem)
{ {
@ -168,12 +176,15 @@ internal sealed class EquipmentBrowserWindow : Window
name += $" {SeIconChar.HighQuality.ToIconString()}"; name += $" {SeIconChar.HighQuality.ToIconString()}";
if (item is InventoryItem { MateriaStats: not null } inventoryItem) if (item is InventoryItem { MateriaStats: not null } inventoryItem)
name += name +=
$" {string.Join("", Enumerable.Repeat(SeIconChar.Circle.ToIconString(), inventoryItem.MateriaStats.Count))}"; $" {string.Join("", Enumerable.Repeat(SeIconChar.Circle.ToIconString(), inventoryItem.MateriaStats!.Count))}";
if (color != null) if (color != null)
ImGui.TextColored(color.Value, name); ImGui.PushStyleColor(ImGuiCol.Text, color.Value);
else
ImGui.Text(name); ImGui.Selectable(name, false, ImGuiSelectableFlags.SpanAllColumns);
if (color != null)
ImGui.PopStyleColor();
if (ImGui.IsItemClicked()) if (ImGui.IsItemClicked())
{ {
@ -215,6 +226,7 @@ internal sealed class EquipmentBrowserWindow : Window
} }
} }
ImGui.PopStyleColor();
ImGui.EndTable(); ImGui.EndTable();
} }
} }

View File

@ -4,9 +4,83 @@
"net8.0-windows7.0": { "net8.0-windows7.0": {
"DalamudPackager": { "DalamudPackager": {
"type": "Direct", "type": "Direct",
"requested": "[2.1.12, )", "requested": "[2.1.13, )",
"resolved": "2.1.12", "resolved": "2.1.13",
"contentHash": "Sc0PVxvgg4NQjcI8n10/VfUQBAS4O+Fw2pZrAqBdRMbthYGeogzu5+xmIGCGmsEZ/ukMOBuAqiNiB5qA3MRalg==" "contentHash": "rMN1omGe8536f4xLMvx9NwfvpAc9YFFfeXJ1t4P4PE6Gu8WCIoFliR1sh07hM+bfODmesk/dvMbji7vNI+B/pQ=="
},
"DotNet.ReproducibleBuilds": {
"type": "Direct",
"requested": "[1.1.1, )",
"resolved": "1.1.1",
"contentHash": "+H2t/t34h6mhEoUvHi8yGXyuZ2GjSovcGYehJrS2MDm2XgmPfZL2Sdxg+uL2lKgZ4M6tTwKHIlxOob2bgh0NRQ==",
"dependencies": {
"Microsoft.SourceLink.AzureRepos.Git": "1.1.1",
"Microsoft.SourceLink.Bitbucket.Git": "1.1.1",
"Microsoft.SourceLink.GitHub": "1.1.1",
"Microsoft.SourceLink.GitLab": "1.1.1"
}
},
"Microsoft.SourceLink.Gitea": {
"type": "Direct",
"requested": "[8.0.0, )",
"resolved": "8.0.0",
"contentHash": "KOBodmDnlWGIqZt2hT47Q69TIoGhIApDVLCyyj9TT5ct8ju16AbHYcB4XeknoHX562wO1pMS/1DfBIZK+V+sxg==",
"dependencies": {
"Microsoft.Build.Tasks.Git": "8.0.0",
"Microsoft.SourceLink.Common": "8.0.0"
}
},
"Microsoft.Build.Tasks.Git": {
"type": "Transitive",
"resolved": "8.0.0",
"contentHash": "bZKfSIKJRXLTuSzLudMFte/8CempWjVamNUR5eHJizsy+iuOuO/k2gnh7W0dHJmYY0tBf+gUErfluCv5mySAOQ=="
},
"Microsoft.SourceLink.AzureRepos.Git": {
"type": "Transitive",
"resolved": "1.1.1",
"contentHash": "qB5urvw9LO2bG3eVAkuL+2ughxz2rR7aYgm2iyrB8Rlk9cp2ndvGRCvehk3rNIhRuNtQaeKwctOl1KvWiklv5w==",
"dependencies": {
"Microsoft.Build.Tasks.Git": "1.1.1",
"Microsoft.SourceLink.Common": "1.1.1"
}
},
"Microsoft.SourceLink.Bitbucket.Git": {
"type": "Transitive",
"resolved": "1.1.1",
"contentHash": "cDzxXwlyWpLWaH0em4Idj0H3AmVo3L/6xRXKssYemx+7W52iNskj/SQ4FOmfCb8YQt39otTDNMveCZzYtMoucQ==",
"dependencies": {
"Microsoft.Build.Tasks.Git": "1.1.1",
"Microsoft.SourceLink.Common": "1.1.1"
}
},
"Microsoft.SourceLink.Common": {
"type": "Transitive",
"resolved": "8.0.0",
"contentHash": "dk9JPxTCIevS75HyEQ0E4OVAFhB2N+V9ShCXf8Q6FkUQZDkgLI12y679Nym1YqsiSysuQskT7Z+6nUf3yab6Vw=="
},
"Microsoft.SourceLink.GitHub": {
"type": "Transitive",
"resolved": "1.1.1",
"contentHash": "IaJGnOv/M7UQjRJks7B6p7pbPnOwisYGOIzqCz5ilGFTApZ3ktOR+6zJ12ZRPInulBmdAf1SrGdDG2MU8g6XTw==",
"dependencies": {
"Microsoft.Build.Tasks.Git": "1.1.1",
"Microsoft.SourceLink.Common": "1.1.1"
}
},
"Microsoft.SourceLink.GitLab": {
"type": "Transitive",
"resolved": "1.1.1",
"contentHash": "tvsg47DDLqqedlPeYVE2lmiTpND8F0hkrealQ5hYltSmvruy/Gr5nHAKSsjyw5L3NeM/HLMI5ORv7on/M4qyZw==",
"dependencies": {
"Microsoft.Build.Tasks.Git": "1.1.1",
"Microsoft.SourceLink.Common": "1.1.1"
}
},
"llib": {
"type": "Project",
"dependencies": {
"DalamudPackager": "[2.1.13, )"
}
} }
} }
} }

1
LLib Submodule

@ -0,0 +1 @@
Subproject commit 9db9f95b8cd3f36262b5b4b14f12b7331d3c7279