Snapshot for release 2026.11.2.1 (internal 03dbb32)

This commit is contained in:
Tom Bohar 2026-11-02 03:33:34 -05:00
commit 79cbb84d61
77 changed files with 8622 additions and 224 deletions

View file

@ -84,6 +84,9 @@ public sealed class RynthSortPlugin : RynthPluginBase
{
Warnings = () => _warnings,
Character = () => _identityKnown ? _character : string.Empty,
Icons = IconsOn,
CanSelect = () => Host.HasSelectItem,
SelectInGame = id => Host.HasSelectItem && Host.SelectItem(id),
};
// No bar button of its own: opened from the engine Inventory window's Sort button, the
// Scripts menu or /rsort.
@ -244,6 +247,14 @@ public sealed class RynthSortPlugin : RynthPluginBase
}
}
// Item icons in script windows need op level 2 (engines from 2026-09-30); asked until it says yes.
private bool _icons;
private bool IconsOn()
{
if (!_icons) _icons = Host.HasUi && Host.TryGetUiInfo(out RynthCore.PluginSdk.UiInfoNative info) && info.OpLevel >= 2;
return _icons;
}
private void TryStartCharacter(long now)
{
_nextIdentityTryMs = now + IdentityRetryMs;

View file

@ -76,10 +76,15 @@ internal sealed class InventoryReader
if (isContainer)
{
// A side pack holds items; foci (containers that hold none) aren't packs or items.
if (capRead && cap > 0)
// A container whose capacity can't be read yet but that has items in it is a pack
// too (foci never hold any): leaving it out would number every pack below it one
// too high against the pack column. Its capacity stays 0 (the planner's 24).
uint[]? inside = null;
if (!capRead) inside = Contents(host, id);
if (IsSidePack(wielded: false, capRead, cap, inside?.Length ?? 0))
{
var pack = new SortPack { Id = id, Capacity = cap, Name = host.TryGetObjectName(id, out string pn) ? pn : string.Empty };
foreach (uint inner in Contents(host, id))
var pack = new SortPack { Id = id, Capacity = capRead ? cap : 0, Name = host.TryGetObjectName(id, out string pn) ? pn : string.Empty };
foreach (uint inner in inside ?? Contents(host, id))
{
if (inner == 0) continue;
uint it = host.TryGetItemType(inner, out uint itt) ? itt : 0;
@ -98,10 +103,41 @@ internal sealed class InventoryReader
foreach (SortPack p in inv.Packs)
if (host.TryGetContainerOrder(p.Id, false, ref _order, out n)) p.ApplyOrder(_order, n);
if (host.TryGetContainerOrder(player, true, ref _order, out n)) inv.ApplyPackOrder(_order, n);
else inv.OrderSource = PackOrderSource.NotSeen;
}
NoteOrderSource(host, inv);
return inv;
}
private PackOrderSource? _loggedSource;
private int _loggedPacks = -1;
/// <summary>One log line whenever where the pack numbers come from changes (a runtime fact the window can't show the log).</summary>
private void NoteOrderSource(RynthCoreHost host, SortInventory inv)
{
if (_loggedSource == inv.OrderSource && _loggedPacks == inv.Packs.Count) return;
_loggedSource = inv.OrderSource;
_loggedPacks = inv.Packs.Count;
try { host.Log("[RynthSort] " + OrderSourceLine(inv)); } catch { }
}
/// <summary>The log line for <see cref="NoteOrderSource"/> (pure).</summary>
internal static string OrderSourceLine(SortInventory inv) => inv.OrderSource switch
{
PackOrderSource.Known => $"pack numbers follow the pack column, top first ({inv.Packs.Count} packs, {inv.ColumnEntries} entries in the column with foci)",
PackOrderSource.Mismatch => $"pack numbers by object id: the engine's pack column list ({inv.ColumnEntries} entries) lacks {inv.MissingFromColumn} of {inv.Packs.Count} packs",
PackOrderSource.NotSeen => $"pack numbers by object id: the engine has no pack column list for this character (it loaded after the login with nothing saved); {inv.Packs.Count} packs",
_ => $"pack numbers by object id: this engine has no slot orders (plugin API 80); {inv.Packs.Count} packs",
};
/// <summary>
/// Whether a container in the main pack is a side pack RynthSort lists (pure): never a worn or
/// wielded one; one whose capacity reads holds items (above 0; a focus holds none); one whose
/// capacity can't be read yet counts when it has items in it (foci never do).
/// </summary>
internal static bool IsSidePack(bool wielded, bool capRead, int capacity, int itemsInside) =>
!wielded && (capRead ? capacity > 0 : itemsInside > 0);
/// <summary>The slot <paramref name="itemId"/> holds in <paramref name="container"/> (the engine's slot order), or -1.</summary>
public int SlotOf(RynthCoreHost host, uint container, uint itemId)
{

View file

@ -32,6 +32,12 @@ internal sealed class SortPack
/// nothing is reordered in this pack.
/// </summary>
public bool OrderKnown;
/// <summary>
/// Where it sits in the pack column, 1 = the top, counting foci too (the column shows both);
/// 0 when the column's order isn't known. Its pack number counts packs only, so the two differ
/// when a focus sits above it.
/// </summary>
public int ColumnSlot;
/// <summary>
/// Puts <see cref="Items"/> in <paramref name="order"/> (the pack's slot order) when that names
@ -118,11 +124,26 @@ internal readonly struct SortSlot
public bool IsPack => Capacity > 0;
}
/// <summary>Where the side packs' numbers come from (what the window tells the player).</summary>
internal enum PackOrderSource
{
/// <summary>The engine has no slot orders (before plugin API 80): numbered by object id.</summary>
NoEngine,
/// <summary>The engine hasn't seen the server's pack list for this character (an engine that
/// loaded after the login and had nothing saved): numbered by object id until the next login.</summary>
NotSeen,
/// <summary>The engine's pack list doesn't name every pack read: numbered by object id.</summary>
Mismatch,
/// <summary>The pack column's order, top first.</summary>
Known,
}
/// <summary>
/// The character's packs: the main pack and the side packs, pack 1 first. With the engine's slot
/// order (API v80) that is the pack column on screen, top first (<see cref="PackOrderKnown"/>);
/// else GetContainerContents' order, by object id. Rules keep the pack's id either way, so a
/// pack keeps its rules whatever its number.
/// else GetContainerContents' order, by object id (which is also the order the engine's own
/// Inventory panel falls back to). Rules keep the pack's id either way, so a pack keeps its
/// rules whatever its number.
/// </summary>
internal sealed class SortInventory
{
@ -136,21 +157,39 @@ internal sealed class SortInventory
public readonly List<SortSlot> Slots = new();
/// <summary><see cref="Packs"/> are in the pack column's order, top first.</summary>
public bool PackOrderKnown;
/// <summary>Why the packs are numbered the way they are.</summary>
public PackOrderSource OrderSource = PackOrderSource.NoEngine;
/// <summary>With <see cref="PackOrderSource.Mismatch"/>: how many packs read the list lacks.</summary>
public int MissingFromColumn;
/// <summary>Entries in the pack column's list (packs and foci) the last time it was read; -1 = no list.</summary>
public int ColumnEntries = -1;
/// <summary>
/// Puts <see cref="Packs"/> in the pack column's order: <paramref name="order"/> is the main
/// pack's side-slot list (packs and foci, top first). Only when it names every pack read; else
/// the packs keep their order and <see cref="PackOrderKnown"/> is false.
/// the packs keep their order, <see cref="PackOrderKnown"/> is false and
/// <see cref="MissingFromColumn"/> says how many it lacks. Each pack's
/// <see cref="SortPack.ColumnSlot"/> is its place in the list (foci counted).
/// </summary>
public bool ApplyPackOrder(IReadOnlyList<uint> order, int count)
{
PackOrderKnown = false;
MissingFromColumn = 0;
ColumnEntries = count;
foreach (SortPack p in Packs) p.ColumnSlot = 0;
var rank = new Dictionary<uint, int>(count);
for (int i = 0; i < count; i++) rank.TryAdd(order[i], i);
foreach (SortPack p in Packs)
if (!rank.ContainsKey(p.Id)) return false;
if (!rank.ContainsKey(p.Id)) MissingFromColumn++;
if (MissingFromColumn > 0)
{
OrderSource = PackOrderSource.Mismatch;
return false;
}
Packs.Sort((a, b) => rank[a.Id].CompareTo(rank[b.Id]));
foreach (SortPack p in Packs) p.ColumnSlot = rank[p.Id] + 1;
PackOrderKnown = true;
OrderSource = PackOrderSource.Known;
return true;
}

View file

@ -96,6 +96,8 @@ internal sealed class PackLine
public bool OrderKnown;
/// <summary>Items out of place in it (0 = in order; only counted when the order is known and ordering is on).</summary>
public int OutOfPlace;
/// <summary>Its place in the pack column, 1 = top, foci counted (<see cref="SortPack.ColumnSlot"/>); 0 = not known.</summary>
public int ColumnSlot;
/// <summary>"Sack (12/24) - Salvage, Gems".</summary>
public string Label => $"{Name} ({Used}/{Capacity}) - {Summary}";
@ -123,6 +125,8 @@ internal sealed class SortView
public PackLine Main = new();
/// <summary>The packs are numbered top to bottom as the pack column shows them (else by object id).</summary>
public bool PackOrderKnown;
/// <summary>Why the packs are numbered as they are (<see cref="SortInventory.OrderSource"/>).</summary>
public PackOrderSource OrderSource = PackOrderSource.NoEngine;
/// <summary>The pass could put items in order (the engine reads slot orders and ordering is on).</summary>
public bool Ordering;
/// <summary>Items a rule wants moved that can't go yet (settling, pack full, pack missing, main full).</summary>
@ -428,6 +432,7 @@ internal sealed class SortPlanner
Summary = p.Summary(),
OrderKnown = p.OrderKnown,
OutOfPlace = ordering && p.OrderKnown ? PackOrder.OutOfPlace(p.Items, kindFirst) : 0,
ColumnSlot = p.ColumnSlot,
};
private static void FillPacks(SortView view, SortInventory inv, bool ordering, bool kindFirst)
@ -437,6 +442,7 @@ internal sealed class SortPlanner
view.Main = LineOf(inv.Main, MainCapacityFallback, ordering, kindFirst);
view.Main.Name = "Main pack";
view.PackOrderKnown = inv.PackOrderKnown;
view.OrderSource = inv.OrderSource;
view.Ordering = ordering;
foreach (SortPack p in inv.Packs) view.Packs.Add(LineOf(p, SideCapacityFallback, ordering, kindFirst));
}

View file

@ -8,9 +8,10 @@ namespace RynthCore.Plugin.RynthSort.Views;
/// <summary>
/// The RynthSort window: the auto-sort box and status, the job buttons, then one collapsing
/// section per side pack ("Pack 1: Sack (12/24) - Components", top pack first) holding that
/// pack's warnings and its rules (A-Z), a section for rules whose pack isn't carried, and the
/// settings. A rule is one row (on/off box, its classes and names); selecting it opens its
/// section per side pack ("Pack 1: Sack (12/24) - Components", top pack first) holding a line
/// that says which pack in the game it is (its icon, "Select in game", and its place in the
/// pack column), that pack's warnings and its rules (A-Z), a section for rules whose pack isn't
/// carried, and the settings. A rule is one row (on/off box, its classes and names); selecting it opens its
/// editor beneath: the classes and names as chips (click one to take it out), a class picker and
/// a name box to add, the pack it sends to, and Remove. Recorded on the pump thread, replayed by
/// the engine.
@ -29,6 +30,15 @@ internal sealed class SortPanel
public Func<IReadOnlyList<string>> Warnings = () => Array.Empty<string>();
/// <summary>The character (blank before login).</summary>
public Func<string> Character = () => string.Empty;
/// <summary>The engine draws item icons in script windows (op level 2).</summary>
public Func<bool> Icons = () => false;
/// <summary>The engine can select objects (else no Select button).</summary>
public Func<bool> CanSelect = () => false;
/// <summary>Selects an object in the game (Host.SelectItem); false when it couldn't.</summary>
public Func<uint, bool> SelectInGame = _ => false;
private uint _selectedPack;
private string _selectNote = string.Empty;
public SortPanel(SortController c, Action save)
{
@ -78,6 +88,14 @@ internal sealed class SortPanel
w.TextColored(UiColors.Amber, "RynthAi's AutoCram also moves loot out of the main pack; turn one of them off");
foreach (string warning in Warnings()) w.TextColored(UiColors.Amber, warning);
string numbering = NumberingNote(view);
if (numbering.Length > 0)
{
w.PushStyleColor(UiFormat.ColText, UiColors.Grey);
w.TextWrapped(numbering);
w.PopStyleColor();
}
Dictionary<int, List<SortRule>> byPack = Group(rules, view);
Dictionary<int, List<string>> conflicts = Conflicts(rules, view);
for (int i = 1; i <= view.Packs.Count; i++)
@ -121,10 +139,11 @@ internal sealed class SortPanel
if (attention) w.PushStyleColor(UiFormat.ColText, UiColors.Amber);
bool open = w.CollapsingHeader($"Pack {number}: {p.Label}", $"pack.{p.Id:X8}", defaultOpen: true);
if (attention) w.PopStyleColor();
w.Tooltip(PackTooltip(view));
w.Tooltip(PackHeaderTooltip(view, number));
if (!open) return;
w.Indent(RowIndent);
DrawWhere(w, view, p, number);
if (full) w.TextColored(UiColors.Amber, "This pack is full: items for it wait where they are");
foreach (string line in warnings) w.TextColored(UiColors.Amber, line);
packRules.Sort(SortRules.CompareForList);
@ -150,6 +169,36 @@ internal sealed class SortPanel
w.Unindent(RowIndent);
}
/// <summary>The pack's first line: its icon, Select in game, and where it is in the pack column.</summary>
private void DrawWhere(UiWindow w, SortView view, PackLine p, int number)
{
if (Icons())
{
w.Image(UiFormat.IconKindObject, p.Id, WhereIcon, WhereIcon);
w.SameLine();
}
if (CanSelect())
{
uint id = p.Id;
string name = p.Name;
w.SmallButton("Select in game", $"select.{id:X8}", () =>
{
_selectedPack = id;
_selectNote = SelectInGame(id) ? $"Selected: the game has your {name} selected now" : "The game didn't take the selection";
});
w.Tooltip(SelectTooltip);
w.SameLine();
}
w.TextDisabled(WhereText(view, p, number));
if (_selectedPack == p.Id && _selectNote.Length > 0) w.TextDisabled(_selectNote);
}
private const float WhereIcon = 20f;
internal const string SelectTooltip =
"Selects this pack in the game, as clicking it in your inventory would, so the game shows you which one it is "
+ "(its name in the selection bar). Nothing moves.";
private void DrawMissing(UiWindow w, SortView view, List<SortRule> rules, List<SortRule> missing)
{
w.PushStyleColor(UiFormat.ColText, UiColors.Amber);
@ -310,13 +359,66 @@ internal sealed class SortPanel
internal static string PackTooltip(SortView view) => view.PackOrderKnown ? PackTooltipTopDown : PackTooltipListOrder;
internal const string PackTooltipTopDown =
"Packs are numbered from the top of the pack column (foci don't count). "
+ "A rule remembers the pack you pick, so adding, moving or emptying packs doesn't change where items go.";
"Pack 1 is the top pack in your inventory's pack column, pack 2 the one below it, and so on (foci don't count). "
+ "A rule remembers the pack itself, so moving, adding or emptying packs never sends items to the wrong one.";
internal const string PackTooltipListOrder =
"A rule remembers the pack you pick, so adding, moving or emptying packs doesn't change where items go. "
+ "Pack numbers count your side packs (not foci) in the client's list order, oldest pack first, "
+ "which can differ from the pack column on screen: go by the name and what's in it.";
"Right now the pack numbers here may not match your inventory's pack column (they go oldest pack first): "
+ "go by the pack's name, its item count and what's in it, or open the pack here and use Select in game. "
+ "A rule remembers the pack itself, so items still go to the right one.";
/// <summary>The header's tooltip: which pack in the game this is, in plain words.</summary>
internal static string PackHeaderTooltip(SortView view, int number)
{
PackLine p = view.Packs[number - 1];
string what = $"Your {p.Name}: {p.Used} of {p.Capacity} items ({p.Summary}).";
string where = view.PackOrderKnown
? $"It is the {Ordinal(number)} pack from the top of your inventory's pack column{SlotAside(p, number)}."
: "Its place in your inventory's pack column isn't known right now, so its number may not match the column.";
return what + " " + where + " Open it here and use Select in game to see it picked out in the game.\n\n" + PackTooltip(view);
}
/// <summary>The pack's first line: "2nd pack from the top of the pack column - 14/24 items", or that it isn't known.</summary>
internal static string WhereText(SortView view, PackLine p, int number)
{
if (view.PackOrderKnown)
return $"{Ordinal(number)} pack from the top of the pack column - {p.Used}/{p.Capacity} items";
return $"Place in the pack column not known - {p.Used}/{p.Capacity} items";
}
/// <summary>
/// " (the game's own inventory window also shows the focus above it, so there it is the 3rd entry)"
/// when foci sit above it in the column: the retail window lists foci among the packs; RynthCore's
/// Inventory panel lists them after the packs, so there the pack number is the row.
/// </summary>
private static string SlotAside(PackLine p, int number)
{
if (p.ColumnSlot <= number) return string.Empty;
int foci = p.ColumnSlot - number;
return $" (the game's own inventory window also shows the {(foci == 1 ? "focus" : foci + " foci")} above it, so there it is the {Ordinal(p.ColumnSlot)} entry)";
}
/// <summary>Above the packs when their numbers aren't the pack column's: why, in plain words; else empty.</summary>
internal static string NumberingNote(SortView view)
{
if (view.Packs.Count == 0 || view.PackOrderKnown) return string.Empty;
string why = view.OrderSource switch
{
PackOrderSource.NotSeen => "RynthCore hasn't seen your pack list since this character logged in (it was reloaded after the login). Log out and back in once to fix it.",
PackOrderSource.Mismatch => "RynthCore's pack list is missing a pack you carry. Log out and back in once to fix it.",
_ => "this RynthCore can't read the pack column's order (it needs plugin API 80).",
};
return "Pack numbers here go oldest pack first, not in your pack column's order: " + why
+ " Until then go by each pack's name and contents, or use Select in game.";
}
/// <summary>1st, 2nd, 3rd, 4th ... 11th, 12th, 13th ... 21st.</summary>
internal static string Ordinal(int n)
{
int t = n % 100;
string suffix = t is >= 11 and <= 13 ? "th" : (n % 10) switch { 1 => "st", 2 => "nd", 3 => "rd", _ => "th" };
return n.ToString(System.Globalization.CultureInfo.InvariantCulture) + suffix;
}
/// <summary>" - in order", " - 3 to put in order", " - order not known": a pack's order as the window says it (empty when ordering is off).</summary>
internal static string OrderNote(SortView view, PackLine p, string lead)