1
0
Fork 0

Add LLib (fixes an API 9 issue in GetAddonById)

master
Liza 2023-10-11 10:52:48 +02:00
parent 4f8d5e99cd
commit c270050c3c
Signed by: liza
GPG Key ID: 7199F8D727D55F67
8 changed files with 32 additions and 56 deletions

3
.gitmodules vendored Normal file
View File

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

1
LLib Submodule

@ -0,0 +1 @@
Subproject commit abbbec4f26b1a8903b0cd7aa04f00d557602eaf3

View File

@ -2,6 +2,8 @@
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Workshoppa", "Workshoppa\Workshoppa.csproj", "{4C2E2AD7-D897-4476-A17A-838932D95223}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Workshoppa", "Workshoppa\Workshoppa.csproj", "{4C2E2AD7-D897-4476-A17A-838932D95223}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LLib", "LLib\LLib.csproj", "{43BFEA08-94E9-491B-9A54-5795B9AFB38E}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -12,5 +14,9 @@ Global
{4C2E2AD7-D897-4476-A17A-838932D95223}.Debug|Any CPU.Build.0 = Debug|Any CPU {4C2E2AD7-D897-4476-A17A-838932D95223}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4C2E2AD7-D897-4476-A17A-838932D95223}.Release|Any CPU.ActiveCfg = Release|Any CPU {4C2E2AD7-D897-4476-A17A-838932D95223}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4C2E2AD7-D897-4476-A17A-838932D95223}.Release|Any CPU.Build.0 = Release|Any CPU {4C2E2AD7-D897-4476-A17A-838932D95223}.Release|Any CPU.Build.0 = Release|Any CPU
{43BFEA08-94E9-491B-9A54-5795B9AFB38E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{43BFEA08-94E9-491B-9A54-5795B9AFB38E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{43BFEA08-94E9-491B-9A54-5795B9AFB38E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{43BFEA08-94E9-491B-9A54-5795B9AFB38E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

View File

@ -10,6 +10,7 @@ using Dalamud.Plugin;
using Dalamud.Plugin.Services; using Dalamud.Plugin.Services;
using FFXIVClientStructs.FFXIV.Client.Game; using FFXIVClientStructs.FFXIV.Client.Game;
using ImGuiNET; using ImGuiNET;
using LLib;
using Workshoppa.GameData; using Workshoppa.GameData;
namespace Workshoppa.Windows; namespace Workshoppa.Windows;
@ -53,6 +54,8 @@ internal sealed class MainWindow : Window
public override void Draw() public override void Draw()
{ {
LImGui.AddPatreonIcon(_pluginInterface);
var currentItem = _configuration.CurrentlyCraftedItem; var currentItem = _configuration.CurrentlyCraftedItem;
if (currentItem != null) if (currentItem != null)
{ {

View File

@ -2,6 +2,7 @@
using System.Linq; using System.Linq;
using Dalamud.Game.ClientState.Objects.Types; using Dalamud.Game.ClientState.Objects.Types;
using FFXIVClientStructs.FFXIV.Component.GUI; using FFXIVClientStructs.FFXIV.Component.GUI;
using LLib.GameUI;
using ValueType = FFXIVClientStructs.FFXIV.Component.GUI.ValueType; using ValueType = FFXIVClientStructs.FFXIV.Component.GUI.ValueType;
namespace Workshoppa; namespace Workshoppa;
@ -91,7 +92,7 @@ partial class WorkshopPlugin
.Select(i => new .Select(i => new
{ {
WorkshopItemId = atkValues[14 + 4 * i].UInt, WorkshopItemId = atkValues[14 + 4 * i].UInt,
Name = ReadAtkString(atkValues[17 + 4 * i]), Name = atkValues[17 + 4 * i].ReadAtkString(),
}) })
.ToList(); .ToList();

View File

@ -10,6 +10,7 @@ using FFXIVClientStructs.FFXIV.Client.Game.Control;
using FFXIVClientStructs.FFXIV.Client.UI; using FFXIVClientStructs.FFXIV.Client.UI;
using FFXIVClientStructs.FFXIV.Client.UI.Agent; using FFXIVClientStructs.FFXIV.Client.UI.Agent;
using FFXIVClientStructs.FFXIV.Component.GUI; using FFXIVClientStructs.FFXIV.Component.GUI;
using LLib.GameUI;
using Workshoppa.GameData; using Workshoppa.GameData;
namespace Workshoppa; namespace Workshoppa;
@ -52,30 +53,10 @@ partial class WorkshopPlugin
return ((FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)obj.Address)->GetNpcID(); return ((FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)obj.Address)->GetNpcID();
} }
private unsafe bool TryGetAddonByName<T>(string addonName, out T* addonPtr)
where T : unmanaged
{
var a = _gameGui.GetAddonByName(addonName);
if (a != IntPtr.Zero)
{
addonPtr = (T*)a;
return true;
}
else
{
addonPtr = null;
return false;
}
}
private unsafe bool IsAddonReady(AtkUnitBase* addon)
{
return addon->IsVisible && addon->UldManager.LoadedState == AtkLoadState.Loaded;
}
private unsafe AtkUnitBase* GetCompanyCraftingLogAddon() private unsafe AtkUnitBase* GetCompanyCraftingLogAddon()
{ {
if (TryGetAddonByName<AtkUnitBase>("CompanyCraftRecipeNoteBook", out var addon) && IsAddonReady(addon)) if (_gameGui.TryGetAddonByName<AtkUnitBase>("CompanyCraftRecipeNoteBook", out var addon) && LAddon.IsAddonReady(addon))
return addon; return addon;
return null; return null;
@ -94,35 +75,18 @@ partial class WorkshopPlugin
if (addonId == 0) if (addonId == 0)
return null; return null;
AtkUnitBase* addon = GetAddonById(addonId); AtkUnitBase* addon = LAddon.GetAddonById(addonId);
if (IsAddonReady(addon)) if (LAddon.IsAddonReady(addon))
return addon; return addon;
} }
return null; return null;
} }
private unsafe AtkUnitBase* GetAddonById(uint id)
{
var unitManagers = &AtkStage.GetSingleton()->RaptureAtkUnitManager->AtkUnitManager.DepthLayerOneList;
for (var i = 0; i < 18; i++)
{
foreach (AtkUnitBase* unitBase in unitManagers[i].EntriesSpan)
{
if (unitBase != null && unitBase->ID == id)
{
return unitBase;
}
}
}
return null;
}
private unsafe bool SelectSelectString(string marker, int choice, Predicate<string> predicate) private unsafe bool SelectSelectString(string marker, int choice, Predicate<string> predicate)
{ {
if (TryGetAddonByName<AddonSelectString>("SelectString", out var addonSelectString) && if (_gameGui.TryGetAddonByName<AddonSelectString>("SelectString", out var addonSelectString) &&
IsAddonReady(&addonSelectString->AtkUnitBase)) LAddon.IsAddonReady(&addonSelectString->AtkUnitBase))
{ {
int entries = addonSelectString->PopupMenu.PopupMenu.EntryCount; int entries = addonSelectString->PopupMenu.PopupMenu.EntryCount;
if (entries < choice) if (entries < choice)
@ -146,8 +110,8 @@ partial class WorkshopPlugin
private unsafe bool SelectSelectYesno(int choice, Predicate<string> predicate) private unsafe bool SelectSelectYesno(int choice, Predicate<string> predicate)
{ {
if (TryGetAddonByName<AddonSelectYesno>("SelectYesno", out var addonSelectYesno) && if (_gameGui.TryGetAddonByName<AddonSelectYesno>("SelectYesno", out var addonSelectYesno) &&
IsAddonReady(&addonSelectYesno->AtkUnitBase)) LAddon.IsAddonReady(&addonSelectYesno->AtkUnitBase))
{ {
var text = MemoryHelper.ReadSeString(&addonSelectYesno->PromptText->NodeText).ToString(); var text = MemoryHelper.ReadSeString(&addonSelectYesno->PromptText->NodeText).ToString();
text = text.Replace("\n", "").Replace("\r", ""); text = text.Replace("\n", "").Replace("\r", "");
@ -166,13 +130,6 @@ partial class WorkshopPlugin
return false; return false;
} }
private unsafe string? ReadAtkString(AtkValue atkValue)
{
if (atkValue.String != null)
return MemoryHelper.ReadSeStringNullTerminated(new nint(atkValue.String)).ToString();
return null;
}
private unsafe CraftState? ReadCraftState(AtkUnitBase* addonMaterialDelivery) private unsafe CraftState? ReadCraftState(AtkUnitBase* addonMaterialDelivery)
{ {
try try
@ -189,7 +146,7 @@ partial class WorkshopPlugin
{ {
ItemId = atkValues[12 + i].UInt, ItemId = atkValues[12 + i].UInt,
IconId = atkValues[24 + i].UInt, IconId = atkValues[24 + i].UInt,
ItemName = ReadAtkString(atkValues[36 + i]), ItemName = atkValues[36 + i].ReadAtkString(),
CrafterIconId = atkValues[48 + i].Int, CrafterIconId = atkValues[48 + i].Int,
ItemCountPerStep = atkValues[60 + i].UInt, ItemCountPerStep = atkValues[60 + i].UInt,
ItemCountNQ = atkValues[72 + i].UInt, ItemCountNQ = atkValues[72 + i].UInt,
@ -223,7 +180,7 @@ partial class WorkshopPlugin
{ {
// NQ / HQ string // NQ / HQ string
// I have no clue, but it doesn't seme like the available HQ item count is strored anywhere in the atkvalues?? // I have no clue, but it doesn't seme like the available HQ item count is strored anywhere in the atkvalues??
string? s = ReadAtkString(atkValue); string? s = atkValue.ReadAtkString();
if (s != null) if (s != null)
{ {
var parts = s.Replace("\ue03c", "").Split('/'); var parts = s.Replace("\ue03c", "").Split('/');

View File

@ -23,6 +23,10 @@
<DalamudLibPath>$(DALAMUD_HOME)/</DalamudLibPath> <DalamudLibPath>$(DALAMUD_HOME)/</DalamudLibPath>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\LLib\LLib.csproj" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="DalamudPackager" Version="2.1.12"/> <PackageReference Include="DalamudPackager" Version="2.1.12"/>
</ItemGroup> </ItemGroup>
@ -58,8 +62,6 @@
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<Target Name="RenameLatestZip" AfterTargets="PackagePlugin" Condition="'$(Configuration)' == 'Release'"> <Target Name="RenameLatestZip" AfterTargets="PackagePlugin" Condition="'$(Configuration)' == 'Release'">
<Exec Command="rename $(OutDir)$(AssemblyName)\latest.zip $(AssemblyName)-$(Version).zip"/> <Exec Command="rename $(OutDir)$(AssemblyName)\latest.zip $(AssemblyName)-$(Version).zip"/>
</Target> </Target>

View File

@ -7,6 +7,9 @@
"requested": "[2.1.12, )", "requested": "[2.1.12, )",
"resolved": "2.1.12", "resolved": "2.1.12",
"contentHash": "Sc0PVxvgg4NQjcI8n10/VfUQBAS4O+Fw2pZrAqBdRMbthYGeogzu5+xmIGCGmsEZ/ukMOBuAqiNiB5qA3MRalg==" "contentHash": "Sc0PVxvgg4NQjcI8n10/VfUQBAS4O+Fw2pZrAqBdRMbthYGeogzu5+xmIGCGmsEZ/ukMOBuAqiNiB5qA3MRalg=="
},
"llib": {
"type": "Project"
} }
} }
} }