C# 12 stuff & ExdSheets

This commit is contained in:
Asriel Camora
2024-06-14 13:21:04 -07:00
parent 14ba80f9fe
commit f6574ae604
14 changed files with 77 additions and 131 deletions
+2 -1
View File
@@ -39,8 +39,9 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="DalamudPackager" Version="2.1.12" /> <PackageReference Include="DalamudPackager" Version="2.1.12" />
<PackageReference Include="ExdSheets" Version="1.0.0" />
<PackageReference Include="MathNet.Numerics" Version="5.0.0" /> <PackageReference Include="MathNet.Numerics" Version="5.0.0" />
<PackageReference Include="Meziantou.Analyzer" Version="2.0.106"> <PackageReference Include="Meziantou.Analyzer" Version="2.0.157">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>
+1 -50
View File
@@ -1,11 +1,9 @@
using Dalamud; using Dalamud;
using ExdSheets;
using Lumina; using Lumina;
using Lumina.Data; using Lumina.Data;
using Lumina.Excel; using Lumina.Excel;
using Lumina.Excel.GeneratedSheets2;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using Action = Lumina.Excel.GeneratedSheets2.Action;
using ItemFood = Lumina.Excel.GeneratedSheets.ItemFood; // BaseParam is too annoying with SoA
namespace Craftimizer.Plugin; namespace Craftimizer.Plugin;
@@ -44,50 +42,3 @@ public static class LuminaSheets
return parser.RowCount; return parser.RowCount;
} }
} }
#nullable disable
[Sheet("SharlayanCraftWorksSupply", columnHash: 0x903b128e)]
public class SharlayanCraftWorksSupply : ExcelRow
{
public class ItemData
{
public byte Level { get; set; }
public LazyRow<Item> Item { get; set; }
public ushort CollectabilityMid { get; set; }
public ushort CollectabilityHigh { get; set; }
public uint XPReward { get; set; }
public byte HighXPMultiplier { get; set; }
public ushort GilReward { get; set; }
public byte HighGilMultiplier { get; set; }
public byte Unknown8 { get; set; }
public byte ScripReward { get; set; }
public byte HighScripMultiplier { get; set; }
}
public ItemData[] Items { get; set; }
public override void PopulateData(RowParser parser, GameData gameData, Language language)
{
base.PopulateData(parser, gameData, language);
Items = new ItemData[4];
for (var i = 0; i < 4; i++)
{
Items[i] = new ItemData();
Items[i].Level = parser.ReadColumn<byte>(0 * 4 + i);
Items[i].Item = new LazyRow<Item>(gameData, parser.ReadColumn<uint>(1 * 4 + i), language);
Items[i].CollectabilityMid = parser.ReadColumn<ushort>(2 * 4 + i);
Items[i].CollectabilityHigh = parser.ReadColumn<ushort>(3 * 4 + i);
Items[i].XPReward = parser.ReadColumn<uint>(4 * 4 + i);
Items[i].HighXPMultiplier = parser.ReadColumn<byte>(5 * 4 + i);
Items[i].GilReward = parser.ReadColumn<ushort>(6 * 4 + i);
Items[i].HighGilMultiplier = parser.ReadColumn<byte>(7 * 4 + i);
Items[i].Unknown8 = parser.ReadColumn<byte>(8 * 4 + i);
Items[i].ScripReward = parser.ReadColumn<byte>(9 * 4 + i);
Items[i].HighScripMultiplier = parser.ReadColumn<byte>(10 * 4 + i);
}
}
}
#nullable restore
+1 -1
View File
@@ -124,7 +124,7 @@ public sealed class Plugin : IDalamudPlugin
public void OpenEmptyMacroEditor() public void OpenEmptyMacroEditor()
{ {
var stats = GetDefaultStats(); var stats = GetDefaultStats();
OpenMacroEditor(stats.Character, stats.Recipe, stats.Buffs, Enumerable.Empty<ActionType>(), null); OpenMacroEditor(stats.Character, stats.Recipe, stats.Buffs, [], null);
} }
public void OpenMacroEditor(CharacterStats characterStats, RecipeData recipeData, MacroEditor.CrafterBuffs buffs, IEnumerable<ActionType> actions, Action<IEnumerable<ActionType>>? setter) public void OpenMacroEditor(CharacterStats characterStats, RecipeData recipeData, MacroEditor.CrafterBuffs buffs, IEnumerable<ActionType> actions, Action<IEnumerable<ActionType>>? setter)
+3 -5
View File
@@ -3,20 +3,18 @@ using Craftimizer.Simulator.Actions;
using Dalamud.Game.Text.SeStringHandling.Payloads; using Dalamud.Game.Text.SeStringHandling.Payloads;
using Dalamud.Interface.Internal; using Dalamud.Interface.Internal;
using Dalamud.Utility; using Dalamud.Utility;
using FFXIVClientStructs.FFXIV.Client.Game;
using FFXIVClientStructs.FFXIV.Client.Game.Object;
using FFXIVClientStructs.FFXIV.Client.Game.UI; using FFXIVClientStructs.FFXIV.Client.Game.UI;
using Lumina.Excel.GeneratedSheets2; using ExdSheets;
using System; using System;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using System.Numerics; using System.Numerics;
using System.Text; using System.Text;
using Action = Lumina.Excel.GeneratedSheets2.Action; using Action = ExdSheets.Action;
using ActionType = Craftimizer.Simulator.Actions.ActionType; using ActionType = Craftimizer.Simulator.Actions.ActionType;
using ClassJob = Craftimizer.Simulator.ClassJob; using ClassJob = Craftimizer.Simulator.ClassJob;
using Condition = Craftimizer.Simulator.Condition; using Condition = Craftimizer.Simulator.Condition;
using Status = Lumina.Excel.GeneratedSheets2.Status; using Status = ExdSheets.Status;
namespace Craftimizer.Plugin; namespace Craftimizer.Plugin;
+2 -3
View File
@@ -297,7 +297,7 @@ public sealed class CommunityMacros
if (!string.IsNullOrEmpty(macro.Name)) if (!string.IsNullOrEmpty(macro.Name))
{ {
if (Uri.TryCreate(macro.Name, UriKind.Relative, out var uri)) if (Uri.TryCreate(macro.Name, UriKind.Relative, out _))
{ {
var rotationId = macro.Name.Split('/')[^1]; var rotationId = macro.Name.Split('/')[^1];
if (!string.IsNullOrEmpty(rotationId)) if (!string.IsNullOrEmpty(rotationId))
@@ -474,8 +474,7 @@ public sealed class CommunityMacros
private static async Task<TResponse?> PostFromJsonAsync<TRequest, TResponse>(HttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, TRequest value, JsonSerializerOptions? options = null, CancellationToken cancellationToken = default) private static async Task<TResponse?> PostFromJsonAsync<TRequest, TResponse>(HttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, TRequest value, JsonSerializerOptions? options = null, CancellationToken cancellationToken = default)
{ {
if (client is null) ArgumentNullException.ThrowIfNull(client);
throw new ArgumentNullException(nameof(client));
var resp = client.PostAsJsonAsync(requestUri, value, options, cancellationToken); var resp = client.PostAsJsonAsync(requestUri, value, options, cancellationToken);
using var message = await resp.ConfigureAwait(false); using var message = await resp.ConfigureAwait(false);
+4 -4
View File
@@ -1,6 +1,6 @@
using Craftimizer.Plugin; using Craftimizer.Plugin;
using Craftimizer.Plugin.Utils; using Craftimizer.Plugin.Utils;
using Lumina.Excel.GeneratedSheets2; using ExdSheets;
using System.Collections.Frozen; using System.Collections.Frozen;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
@@ -63,12 +63,12 @@ public static class FoodStatus
continue; continue;
FoodStat? craftsmanship = null, control = null, cp = null; FoodStat? craftsmanship = null, control = null, cp = null;
foreach (var stat in itemFood.UnkData1) foreach (var stat in itemFood.Params)
{ {
if (stat.BaseParam == 0) if (stat.BaseParam.Row == 0)
continue; continue;
var foodStat = new FoodStat(stat.IsRelative, stat.Value, stat.Max, stat.ValueHQ, stat.MaxHQ); var foodStat = new FoodStat(stat.IsRelative, stat.Value, stat.Max, stat.ValueHQ, stat.MaxHQ);
switch ((uint)stat.BaseParam) switch (stat.BaseParam.Row)
{ {
case Gearsets.ParamCraftsmanship: craftsmanship = foodStat; break; case Gearsets.ParamCraftsmanship: craftsmanship = foodStat; break;
case Gearsets.ParamControl: control = foodStat; break; case Gearsets.ParamControl: control = foodStat; break;
+1 -1
View File
@@ -50,7 +50,7 @@ internal readonly struct FuzzyMatcher
if (wordStart >= 0) if (wordStart >= 0)
segments.Add((wordStart, span.Length - 1)); segments.Add((wordStart, span.Length - 1));
return segments.ToArray(); return [.. segments];
} }
public int Matches(string value) public int Matches(string value)
+1 -1
View File
@@ -3,7 +3,7 @@ using Dalamud.Utility;
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 Lumina.Excel.GeneratedSheets2; using ExdSheets;
using System; using System;
using System.Linq; using System.Linq;
+5 -8
View File
@@ -83,15 +83,12 @@ public static class MacroImport
if (!TryParseUrl(url, out var uri)) if (!TryParseUrl(url, out var uri))
throw new ArgumentException("Unsupported url", nameof(url)); throw new ArgumentException("Unsupported url", nameof(url));
switch (uri.DnsSafeHost) return uri.DnsSafeHost switch
{ {
case "ffxivteamcraft.com": "ffxivteamcraft.com" => RetrieveTeamcraftUrl(uri, token),
return RetrieveTeamcraftUrl(uri, token); "craftingway.app" => RetrieveCraftingwayUrl(uri, token),
case "craftingway.app": _ => throw new UnreachableException("TryParseUrl should handle miscellaneous edge cases"),
return RetrieveCraftingwayUrl(uri, token); };
default:
throw new UnreachableException("TryParseUrl should handle miscellaneous edge cases");
}
} }
private static async Task<CommunityMacro> RetrieveTeamcraftUrl(Uri uri, CancellationToken token) private static async Task<CommunityMacro> RetrieveTeamcraftUrl(Uri uri, CancellationToken token)
+33 -45
View File
@@ -1,6 +1,7 @@
using Craftimizer.Plugin; using Craftimizer.Plugin;
using Craftimizer.Simulator; using Craftimizer.Simulator;
using Lumina.Excel.GeneratedSheets2; using ExdSheets;
using Lumina.Excel;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@@ -47,58 +48,47 @@ public sealed record RecipeData
}; };
CollectableThresholds = null; CollectableThresholds = null;
switch (Recipe.Unknown1) if (Recipe.CollectableMetadata is LazyRow<CollectablesShopRefine> { Value: { } row })
CollectableThresholds = new int?[] { row.LowCollectability, row.MidCollectability, row.HighCollectability };
else if (Recipe.CollectableMetadata is LazyRow<HWDCrafterSupply> { Value: { } row2 })
{ {
case 1: foreach (var entry in row2.HWDCrafterSupplyParams)
var data1 = LuminaSheets.CollectablesShopRefineSheet.GetRow(Recipe.Unknown0); {
if (data1 == null) if (entry.ItemTradeIn.Row == Recipe.ItemResult.Row)
break;
CollectableThresholds = new int?[] { data1.LowCollectability, data1.MidCollectability, data1.HighCollectability };
break;
case 2:
var data2 = LuminaSheets.HWDCrafterSupplySheet.GetRow(Recipe.Unknown0);
if (data2 == null)
break;
foreach (var entry in data2.HWDCrafterSupplyParams)
{ {
if (entry.ItemTradeIn.Row == Recipe.ItemResult.Row) CollectableThresholds = new int?[] { entry.BaseCollectableRating, entry.MidCollectableRating, entry.HighCollectableRating };
{
CollectableThresholds = new int?[] { entry.BaseCollectableRating, entry.MidCollectableRating, entry.HighCollectableRating };
break;
}
}
break;
case 3:
var subRowCount = LuminaSheets.SatisfactionSupplySheet.GetSubRowCount(Recipe.Unknown0);
if (subRowCount is not { } subRowValue)
break; break;
}
}
}
else if (Recipe.CollectableMetadata is LazyRow<SatisfactionSupply> { } row4)
{
var subRowCount = LuminaSheets.SatisfactionSupplySheet.GetSubRowCount(row4.Row);
if (subRowCount is { } subRowValue)
{
for (uint i = 0; i < subRowValue; ++i) for (uint i = 0; i < subRowValue; ++i)
{ {
var data3 = LuminaSheets.SatisfactionSupplySheet.GetRow(Recipe.Unknown0, i); var subRow = LuminaSheets.SatisfactionSupplySheet.GetRow(row4.Row, i);
if (data3 == null) if (subRow == null)
continue; continue;
if (data3.Item.Row == Recipe.ItemResult.Row) if (subRow.Item.Row == Recipe.ItemResult.Row)
{ {
CollectableThresholds = new int?[] { data3.CollectabilityLow, data3.CollectabilityMid, data3.CollectabilityHigh }; CollectableThresholds = new int?[] { subRow.CollectabilityLow, subRow.CollectabilityMid, subRow.CollectabilityHigh };
break; break;
} }
} }
break; }
case 4: }
var data4 = LuminaSheets.SharlayanCraftWorksSupplySheet.GetRow(Recipe.Unknown0); else if (Recipe.CollectableMetadata is LazyRow<SharlayanCraftWorksSupply> { Value: { } row5 })
if (data4 == null) {
break; foreach (var item in row5.Item)
foreach (var item in data4.Items) {
if (item.Id == Recipe.ItemResult.Row)
{ {
if (item.Item.Row == Recipe.ItemResult.Row) CollectableThresholds = new int?[] { null, item.CollectabilityMid, item.CollectabilityHigh };
{ break;
CollectableThresholds = new int?[] { null, item.CollectabilityMid, item.CollectabilityHigh };
break;
}
} }
break; }
default:
break;
} }
Ingredients = Recipe.Ingredient.Zip(Recipe.AmountIngredient) Ingredients = Recipe.Ingredient.Zip(Recipe.AmountIngredient)
@@ -113,12 +103,10 @@ public sealed record RecipeData
public int CalculateItemStartingQuality(int itemIdx, int amount) public int CalculateItemStartingQuality(int itemIdx, int amount)
{ {
if (itemIdx >= Ingredients.Count) ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(itemIdx, Ingredients.Count);
throw new ArgumentOutOfRangeException(nameof(itemIdx));
var ingredient = Ingredients[itemIdx]; var ingredient = Ingredients[itemIdx];
if (amount > ingredient.Amount) ArgumentOutOfRangeException.ThrowIfGreaterThan(amount, ingredient.Amount);
throw new ArgumentOutOfRangeException(nameof(amount));
if (!ingredient.Item.CanBeHq) if (!ingredient.Item.CanBeHq)
return 0; return 0;
+1 -1
View File
@@ -67,7 +67,7 @@ internal sealed unsafe class SynthesisValues(AddonSynthesis* addon)
var value = Values[i]; var value = Values[i];
return value.Type switch return value.Type switch
{ {
ValueType.AllocatedString or ValueType.ManagedString or
ValueType.String => ValueType.String =>
MemoryHelper.ReadSeStringNullTerminated((nint)value.String), MemoryHelper.ReadSeStringNullTerminated((nint)value.String),
_ => null _ => null
+3 -3
View File
@@ -1060,12 +1060,12 @@ public sealed class MacroEditor : Window, IDisposable
DynamicBars.Draw(datas); DynamicBars.Draw(datas);
ImGui.TableNextColumn(); ImGui.TableNextColumn();
datas = new List<DynamicBars.BarData>(3) datas =
{ [
new("Progress", Colors.Progress, Reliability.Progress, State.Progress, RecipeData.RecipeInfo.MaxProgress), new("Progress", Colors.Progress, Reliability.Progress, State.Progress, RecipeData.RecipeInfo.MaxProgress),
new("Quality", Colors.Quality, Reliability.Quality, State.Quality, RecipeData.RecipeInfo.MaxQuality), new("Quality", Colors.Quality, Reliability.Quality, State.Quality, RecipeData.RecipeInfo.MaxQuality),
new("CP", Colors.CP, State.CP, CharacterStats.CP) new("CP", Colors.CP, State.CP, CharacterStats.CP)
}; ];
if (RecipeData.RecipeInfo.MaxQuality <= 0) if (RecipeData.RecipeInfo.MaxQuality <= 0)
datas.RemoveAt(1); datas.RemoveAt(1);
DynamicBars.Draw(datas); DynamicBars.Draw(datas);
+3 -5
View File
@@ -401,7 +401,7 @@ public sealed unsafe class RecipeNote : Window, IDisposable
Service.Plugin.OpenMacroListWindow(); Service.Plugin.OpenMacroListWindow();
if (ImGui.Button("Open in Macro Editor", new(availWidth, 0))) if (ImGui.Button("Open in Macro Editor", new(availWidth, 0)))
Service.Plugin.OpenMacroEditor(CharacterStats!, RecipeData!, new(Service.ClientState.LocalPlayer!.StatusList), Enumerable.Empty<ActionType>(), null); Service.Plugin.OpenMacroEditor(CharacterStats!, RecipeData!, new(Service.ClientState.LocalPlayer!.StatusList), [], null);
} }
private void DrawCharacterStats() private void DrawCharacterStats()
@@ -978,8 +978,7 @@ public sealed unsafe class RecipeNote : Window, IDisposable
private static void DrawRequiredStatsTable(int current, int required) private static void DrawRequiredStatsTable(int current, int required)
{ {
if (current >= required) ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(current, required);
throw new ArgumentOutOfRangeException(nameof(current));
using var table = ImRaii.Table("requiredStats", 2); using var table = ImRaii.Table("requiredStats", 2);
if (table) if (table)
@@ -1048,8 +1047,7 @@ public sealed unsafe class RecipeNote : Window, IDisposable
return (ResolveNpcResidentName(level.Object.Row), territory, location, new(level.Territory.Row, level.Map.Row, location.X, location.Y)); return (ResolveNpcResidentName(level.Object.Row), territory, location, new(level.Territory.Row, level.Map.Row, location.X, location.Y));
} }
// MapUtil.WorldToMap but for GeneratedSheets2 private static Vector2 WorldToMap2(Vector2 worldCoordinates, ExdSheets.Map map)
private static Vector2 WorldToMap2(Vector2 worldCoordinates, Lumina.Excel.GeneratedSheets2.Map map)
{ {
return MapUtil.WorldToMap(worldCoordinates, map.OffsetX, map.OffsetY, map.SizeFactor); return MapUtil.WorldToMap(worldCoordinates, map.OffsetX, map.OffsetY, map.SizeFactor);
} }
+17 -3
View File
@@ -8,6 +8,15 @@
"resolved": "2.1.12", "resolved": "2.1.12",
"contentHash": "Sc0PVxvgg4NQjcI8n10/VfUQBAS4O+Fw2pZrAqBdRMbthYGeogzu5+xmIGCGmsEZ/ukMOBuAqiNiB5qA3MRalg==" "contentHash": "Sc0PVxvgg4NQjcI8n10/VfUQBAS4O+Fw2pZrAqBdRMbthYGeogzu5+xmIGCGmsEZ/ukMOBuAqiNiB5qA3MRalg=="
}, },
"ExdSheets": {
"type": "Direct",
"requested": "[1.0.0, )",
"resolved": "1.0.0",
"contentHash": "Zf1btj6qUkrzEm+MVCd2vRWguXizb+Ucy49xWHhFJ5HQj6gtLOxAX2gJqebAtg/uDBbEb9BHx/5Kz7Kuha5+cw==",
"dependencies": {
"Lumina": "3.15.2"
}
},
"MathNet.Numerics": { "MathNet.Numerics": {
"type": "Direct", "type": "Direct",
"requested": "[5.0.0, )", "requested": "[5.0.0, )",
@@ -16,9 +25,14 @@
}, },
"Meziantou.Analyzer": { "Meziantou.Analyzer": {
"type": "Direct", "type": "Direct",
"requested": "[2.0.106, )", "requested": "[2.0.157, )",
"resolved": "2.0.106", "resolved": "2.0.157",
"contentHash": "ygz0oT+Sfkn7Zfhf05iQkrLsrhH9+laOHsab8zq1okOVNjWGbQsXIBgeITF1DLEB/gVYgHHyVEK8YoNnhed/GQ==" "contentHash": "gQ9xAHvpYeqwOqcyRs5f8kFrTt7Kg2atzjsETGhRjuyGXqKYrN84n52Je6NcGEkZWRwhrQTBJl1wlcsh2se7Fw=="
},
"Lumina": {
"type": "Transitive",
"resolved": "3.15.2",
"contentHash": "EnoxYEYMepcvAoXdZhaFJiv2aiDBIPjgkgzxR/+ArOxlrALzCgheTsb5yD39a9sxNIi2tNECT93ulZvYjx8fZg=="
}, },
"craftimizer.simulator": { "craftimizer.simulator": {
"type": "Project" "type": "Project"