RynthCore as of 2026-09-27 (internal d359eee): items past the old object-id range, no idle logoff, overlay popups without the panel flash, UI hidden at character select, vendor trading (API 67), Settings rows and Vendoring tab, release 2026.9.27.2

This commit is contained in:
Tom Bohar 2026-09-27 20:25:45 -04:00
commit 9b5e2765b7
43 changed files with 4216 additions and 62 deletions

View file

@ -119,4 +119,10 @@ public struct RynthCoreApiNative
public IntPtr SendPluginCommandFn; // v64: forward (action,value) to a named plugin's command export
public IntPtr GetObjectDataIdPropertyFn; // v65: read a PWD DataID property (Icon=8 → _iconID) for inventory icons
public IntPtr GetPluginExportJsonFn; // v66: broker any RynthPluginGet*Json export on a named plugin
// v67: vendor trading (see VendorTypes.cs / RynthCoreHost vendor section)
public IntPtr GetVendorInfoFn; // int GetVendorInfo(VendorInfoNative*)
public IntPtr GetVendorItemsFn; // int GetVendorItems(VendorItemNative*, int maxCount)
public IntPtr VendorBuyFn; // uint VendorBuy(uint vendorId, VendorTradeEntryNative*, int count)
public IntPtr VendorSellFn; // uint VendorSell(uint vendorId, uint* itemIds, int count)
public IntPtr GetVendorTradeStatusFn; // int GetVendorTradeStatus(VendorTradeStatusNative*)
}

View file

@ -1,11 +1,23 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace RynthCore.PluginSdk;
public readonly unsafe struct RynthCoreHost
{
public const uint CurrentApiVersion = 66;
public const uint CurrentApiVersion = 67;
/// <summary>
/// The oldest engine API a plugin built on this SDK loads on by default
/// (<see cref="RynthCore.PluginCore.RynthPluginBase.MinimumApiVersion"/>). Players get
/// plugin updates automatically but engine updates only when they click, so defaulting
/// to <see cref="CurrentApiVersion"/> made every rebuilt plugin refuse the engine most
/// players still run. Calls newer than this are version-checked by their wrappers
/// (e.g. HasVendorTrade); a plugin that truly needs a newer engine overrides
/// MinimumApiVersion. Raise this only with a release that forces the engine update.
/// </summary>
public const uint BaselineApiVersion = 66;
private readonly RynthCoreApiNative _api;
@ -1446,4 +1458,206 @@ public readonly unsafe struct RynthCoreHost
Marshal.FreeHGlobal(valuePtr);
}
}
// ─── Vendor trading (API v67) ──────────────────────────────────────────
// Decal's WorldFilter.OpenVendor + Actions.VendorBuyAll/VendorSellAll shape as
// stateless calls (VendorCart adds the Add/Clear list shape on top). Reads come
// from a snapshot the engine takes on AC's main thread when the vendor list
// arrives. Buy/sell are checked, queued, re-checked on AC's main thread (funds,
// pack slots, burden, ownership) and sent through the client's own
// gmVendorUI::SendShopEvent. One transaction is in flight at a time: wait for
// GetVendorTradeStatus to finish before sending the next batch.
/// <summary>True when the engine exposes vendor trading (API v67+).</summary>
public bool HasVendorTrade => _api.Version >= 67
&& _api.GetVendorInfoFn != IntPtr.Zero && _api.GetVendorItemsFn != IntPtr.Zero
&& _api.VendorBuyFn != IntPtr.Zero && _api.VendorSellFn != IntPtr.Zero
&& _api.GetVendorTradeStatusFn != IntPtr.Zero;
/// <summary>The vendor that is open right now, or false if none (or pre-v67 engine).</summary>
public bool TryGetVendorInfo(out VendorInfo info)
{
info = null!;
if (_api.Version < 67 || _api.GetVendorInfoFn == IntPtr.Zero)
return false;
VendorInfoNative raw;
if (((delegate* unmanaged[Cdecl]<VendorInfoNative*, int>)_api.GetVendorInfoFn)(&raw) == 0)
return false;
info = new VendorInfo
{
VendorId = raw.VendorId,
Name = ReadAnsi(raw.Name, 64),
Generation = raw.Generation,
ShopMode = raw.ShopMode,
ItemTypes = raw.ItemTypes,
MinValue = raw.MinValue,
MaxValue = raw.MaxValue,
DealsMagic = raw.DealsMagic != 0,
BuyRate = raw.BuyRate,
SellRate = raw.SellRate,
AltCurrencyWcid = raw.AltCurrencyWcid,
AltCurrencyName = ReadAnsi(raw.AltCurrencyName, 64),
AltCurrencyServerCount = raw.AltCurrencyServerCount,
AltCurrencyHave = raw.AltCurrencyHave,
PlayerCoins = raw.PlayerCoins,
ItemCount = raw.ItemCount,
TradingAvailable = (raw.Flags & 1u) != 0,
TradeInFlight = (raw.Flags & 2u) != 0,
};
return true;
}
/// <summary>The open vendor's items; empty if no vendor is open (or pre-v67 engine).</summary>
public VendorItem[] GetVendorItems()
{
if (_api.Version < 67 || _api.GetVendorItemsFn == IntPtr.Zero)
return Array.Empty<VendorItem>();
var fn = (delegate* unmanaged[Cdecl]<VendorItemNative*, int, int>)_api.GetVendorItemsFn;
for (int attempt = 0; attempt < 3; attempt++)
{
int total = fn(null, 0);
if (total <= 0)
return Array.Empty<VendorItem>();
int capacity = total + 8; // headroom in case the list is re-sent between calls
IntPtr buf = Marshal.AllocHGlobal(capacity * sizeof(VendorItemNative));
try
{
VendorItemNative* items = (VendorItemNative*)buf;
int now = fn(items, capacity);
if (now < 0)
return Array.Empty<VendorItem>();
if (now > capacity)
continue; // grew past the headroom; size again
var result = new VendorItem[now];
for (int i = 0; i < now; i++)
{
VendorItemNative* it = items + i;
result[i] = new VendorItem
{
ObjectId = it->ObjectId,
Wcid = it->Wcid,
Name = ReadAnsi(it->Name, 64),
ItemType = it->ItemType,
IconId = it->IconId,
Amount = it->Amount,
StackSize = it->StackSize,
MaxStackSize = it->MaxStackSize,
Value = it->Value,
UnitValue = it->UnitValue,
UnitPrice = it->UnitPrice,
Burden = it->Burden,
Unlimited = (it->Flags & 1u) != 0,
Stackable = (it->Flags & 2u) != 0,
NeedsContainerSlot = (it->Flags & 4u) != 0,
};
}
return result;
}
finally
{
Marshal.FreeHGlobal(buf);
}
}
return Array.Empty<VendorItem>();
}
/// <summary>
/// Buy from the open vendor (Decal VendorBuyAll). vendorId 0 = whichever vendor is
/// open; pass the id you read to make sure it's still that vendor. Returns the request
/// id, or 0 if refused (reason in <see cref="TryGetVendorTradeStatus"/>).
/// </summary>
public uint VendorBuy(uint vendorId, IReadOnlyList<VendorTradeEntryNative> items)
{
if (_api.Version < 67 || _api.VendorBuyFn == IntPtr.Zero || items == null || items.Count == 0)
return 0;
int n = items.Count;
IntPtr buf = Marshal.AllocHGlobal(n * sizeof(VendorTradeEntryNative));
try
{
VendorTradeEntryNative* p = (VendorTradeEntryNative*)buf;
for (int i = 0; i < n; i++)
p[i] = items[i];
return ((delegate* unmanaged[Cdecl]<uint, VendorTradeEntryNative*, int, uint>)_api.VendorBuyFn)(vendorId, p, n);
}
finally
{
Marshal.FreeHGlobal(buf);
}
}
/// <summary>Buy <paramref name="amount"/> of one vendor item.</summary>
public uint VendorBuy(uint objectId, int amount, uint vendorId = 0) =>
VendorBuy(vendorId, new[] { new VendorTradeEntryNative(objectId, amount) });
/// <summary>
/// Sell your own items (whole stacks) to the open vendor (Decal VendorSellAll).
/// Items must be in your packs, not equipped, and of a type the vendor buys.
/// Returns the request id, or 0 if refused.
/// </summary>
public uint VendorSell(uint vendorId, IReadOnlyList<uint> itemIds)
{
if (_api.Version < 67 || _api.VendorSellFn == IntPtr.Zero || itemIds == null || itemIds.Count == 0)
return 0;
int n = itemIds.Count;
IntPtr buf = Marshal.AllocHGlobal(n * sizeof(uint));
try
{
uint* p = (uint*)buf;
for (int i = 0; i < n; i++)
p[i] = itemIds[i];
return ((delegate* unmanaged[Cdecl]<uint, uint*, int, uint>)_api.VendorSellFn)(vendorId, p, n);
}
finally
{
Marshal.FreeHGlobal(buf);
}
}
/// <summary>Sell one of your items.</summary>
public uint VendorSell(uint itemId) => VendorSell(0, new[] { itemId });
/// <summary>State of the most recent buy/sell request (check RequestId is yours).</summary>
public bool TryGetVendorTradeStatus(out VendorTradeStatus status)
{
status = null!;
if (_api.Version < 67 || _api.GetVendorTradeStatusFn == IntPtr.Zero)
return false;
VendorTradeStatusNative raw;
if (((delegate* unmanaged[Cdecl]<VendorTradeStatusNative*, int>)_api.GetVendorTradeStatusFn)(&raw) == 0)
return false;
status = new VendorTradeStatus
{
RequestId = raw.RequestId,
State = (VendorTradeState)raw.State,
Result = (VendorTradeResult)raw.Result,
IsBuy = raw.IsBuy != 0,
VendorId = raw.VendorId,
EntryCount = raw.EntryCount,
Estimate = raw.Estimate,
Message = ReadAnsi(raw.Message, 128),
};
return true;
}
private static string ReadAnsi(byte* p, int capacity)
{
int len = 0;
while (len < capacity && p[len] != 0)
len++;
if (len == 0)
return string.Empty;
var chars = new char[len];
for (int i = 0; i < len; i++)
chars[i] = (char)p[i]; // Latin-1, the client's single-byte names
return new string(chars);
}
}

View file

@ -0,0 +1,238 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace RynthCore.PluginSdk;
// ─── Vendor trading ABI structs (engine API v67) ────────────────────────────
// Must mirror RynthCore.Engine/Plugins/PluginContract.cs exactly (Pack=4, same
// field order, same fixed-buffer sizes). Plugins normally use the managed
// VendorInfo / VendorItem / VendorTradeStatus types below instead.
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public unsafe struct VendorInfoNative
{
public uint VendorId;
public uint Generation;
public int ShopMode;
public uint ItemTypes;
public int MinValue;
public int MaxValue;
public int DealsMagic;
public float BuyRate;
public float SellRate;
public uint AltCurrencyWcid;
public int AltCurrencyServerCount;
public int AltCurrencyHave;
public int PlayerCoins;
public int ItemCount;
public uint Flags;
public uint Reserved0;
public fixed byte Name[64];
public fixed byte AltCurrencyName[64];
}
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public unsafe struct VendorItemNative
{
public uint ObjectId;
public uint Wcid;
public uint ItemType;
public uint IconId;
public int Amount;
public int StackSize;
public int MaxStackSize;
public int Value;
public int UnitValue;
public int UnitPrice;
public int Burden;
public uint Flags;
public uint Reserved0;
public uint Reserved1;
public fixed byte Name[64];
}
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct VendorTradeEntryNative
{
public uint ObjectId;
public int Amount;
public VendorTradeEntryNative(uint objectId, int amount)
{
ObjectId = objectId;
Amount = amount;
}
}
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public unsafe struct VendorTradeStatusNative
{
public uint RequestId;
public int State;
public int Result;
public int IsBuy;
public uint VendorId;
public int EntryCount;
public int Estimate;
public uint Reserved0;
public fixed byte Message[128];
}
// ─── Managed views ──────────────────────────────────────────────────────────
/// <summary>The vendor that is open right now (Decal: WorldFilter.OpenVendor).</summary>
public sealed class VendorInfo
{
public uint VendorId { get; init; }
public string Name { get; init; } = string.Empty;
/// <summary>Bumps each time the server (re)sends the vendor list: on open and after every accepted buy/sell.</summary>
public uint Generation { get; init; }
public int ShopMode { get; init; }
/// <summary>ITEM_TYPE mask of what the vendor will buy from you.</summary>
public uint ItemTypes { get; init; }
public int MinValue { get; init; }
public int MaxValue { get; init; }
public bool DealsMagic { get; init; }
/// <summary>The vendor pays value x BuyRate when you sell (promissory notes at 1.0).</summary>
public float BuyRate { get; init; }
/// <summary>The vendor charges value x SellRate when you buy (promissory notes at 1.15).</summary>
public float SellRate { get; init; }
/// <summary>WCID of the currency this vendor takes; 0 = pyreals.</summary>
public uint AltCurrencyWcid { get; init; }
public string AltCurrencyName { get; init; } = string.Empty;
/// <summary>Alt currency count as the server put it in the vendor list (-1 if none).</summary>
public int AltCurrencyServerCount { get; init; }
/// <summary>Alt currency the engine counted in your packs (-1 = not counted yet / not an alt-currency vendor).</summary>
public int AltCurrencyHave { get; init; }
/// <summary>Your pyreals (CoinValue), refreshed on AC's main thread; -1 unknown.</summary>
public int PlayerCoins { get; init; }
public int ItemCount { get; init; }
/// <summary>The engine can trade with this vendor (client functions found, layout checked).</summary>
public bool TradingAvailable { get; init; }
/// <summary>A buy/sell is queued or waiting for the server.</summary>
public bool TradeInFlight { get; init; }
public bool UsesAltCurrency => AltCurrencyWcid != 0;
public bool Buys(uint itemType) => (ItemTypes & itemType) != 0;
}
/// <summary>One item on the open vendor's list.</summary>
public sealed class VendorItem
{
public uint ObjectId { get; init; }
public uint Wcid { get; init; }
public string Name { get; init; } = string.Empty;
public uint ItemType { get; init; }
public uint IconId { get; init; }
/// <summary>How many the vendor has; -1 = unlimited.</summary>
public int Amount { get; init; }
public int StackSize { get; init; }
public int MaxStackSize { get; init; }
/// <summary>Value of the listed stack.</summary>
public int Value { get; init; }
public int UnitValue { get; init; }
/// <summary>What one unit costs you at this vendor (server rounding).</summary>
public int UnitPrice { get; init; }
public int Burden { get; init; }
public bool Unlimited { get; init; }
public bool Stackable { get; init; }
/// <summary>Packs and foci need a container slot.</summary>
public bool NeedsContainerSlot { get; init; }
}
/// <summary>Outcome of the most recent VendorBuy / VendorSell request.</summary>
public sealed class VendorTradeStatus
{
public uint RequestId { get; init; }
public VendorTradeState State { get; init; }
public VendorTradeResult Result { get; init; }
public bool IsBuy { get; init; }
public uint VendorId { get; init; }
public int EntryCount { get; init; }
/// <summary>Buy: estimated cost (pyreals or alt currency). Sell: estimated payout in pyreals.</summary>
public int Estimate { get; init; }
public string Message { get; init; } = string.Empty;
/// <summary>Finished one way or the other (done or refused).</summary>
public bool IsFinished => State is VendorTradeState.Done or VendorTradeState.Refused;
public bool Succeeded => State == VendorTradeState.Done && Result == VendorTradeResult.Accepted;
}
public enum VendorTradeState
{
None = 0,
/// <summary>Passed the snapshot checks; waiting for AC's main thread.</summary>
Queued = 1,
/// <summary>Sent through the client; waiting for the server.</summary>
Sent = 2,
/// <summary>The server answered (see Result).</summary>
Done = 3,
/// <summary>Never sent: no vendor, unknown item, not enough money/space/burden, ... (see Message).</summary>
Refused = 4,
}
public enum VendorTradeResult
{
None = 0,
/// <summary>The server re-sent the vendor list: the trade went through.</summary>
Accepted = 1,
/// <summary>The server answered without re-sending the list: it refused (busy, funds, space...).</summary>
AnsweredNoRefresh = 2,
/// <summary>No answer within 10 s.</summary>
TimedOut = 3,
}
/// <summary>
/// Decal-shaped buy/sell lists (Actions.VendorAddBuyList / VendorBuyAll / VendorClearBuyList
/// and the Sell equivalents) on top of the stateless engine calls. Plugin-local: each
/// plugin keeps its own cart. BuyAll/SellAll send the whole list as ONE transaction
/// (max 100 lines) and return the request id (0 = refused, see GetVendorTradeStatus);
/// the list is cleared only when the request is accepted for sending.
/// Wait for the status to finish (and the vendor Generation to bump) before the next batch.
/// </summary>
public sealed class VendorCart
{
private readonly List<VendorTradeEntryNative> _buy = new();
private readonly List<uint> _sell = new();
public IReadOnlyList<VendorTradeEntryNative> BuyList => _buy;
public IReadOnlyList<uint> SellList => _sell;
/// <summary>Add (or top up) a vendor item on the buy list.</summary>
public void AddBuy(uint objectId, int amount)
{
if (objectId == 0 || amount <= 0) return;
for (int i = 0; i < _buy.Count; i++)
{
if (_buy[i].ObjectId == objectId)
{
_buy[i] = new VendorTradeEntryNative(objectId, _buy[i].Amount + amount);
return;
}
}
_buy.Add(new VendorTradeEntryNative(objectId, amount));
}
/// <summary>Add one of your own items (whole stack) to the sell list.</summary>
public void AddSell(uint objectId)
{
if (objectId != 0 && !_sell.Contains(objectId))
_sell.Add(objectId);
}
public void ClearBuy() => _buy.Clear();
public void ClearSell() => _sell.Clear();
public uint BuyAll(RynthCoreHost host, uint vendorId = 0)
{
uint id = host.VendorBuy(vendorId, _buy);
if (id != 0) _buy.Clear();
return id;
}
public uint SellAll(RynthCoreHost host, uint vendorId = 0)
{
uint id = host.VendorSell(vendorId, _sell);
if (id != 0) _sell.Clear();
return id;
}
}