RynthCore as of 2026-11-26 (internal 5e4b1f3): release 2026.11.26.1

This commit is contained in:
Tom Bohar 2026-11-26 22:32:30 -05:00
commit 2ff89683f4
75 changed files with 3838 additions and 173 deletions

View file

@ -24,6 +24,8 @@ internal static class Program
Pricing();
WiringPinned();
BuyBox();
BuyBoxWiringPinned();
Console.WriteLine(_failed == 0 ? $"PASS ({_checks} checks)" : $"FAIL ({_failed} of {_checks} checks failed)");
return _failed == 0 ? 0 : 1;
@ -77,6 +79,100 @@ internal static class Program
Check(text.Contains(needle, StringComparison.Ordinal), "VendorTrade.cs contains: " + needle);
}
// The Inventory panel's "Buy how many?" box (VendorBuyMath, 2026-11-26).
private static void BuyBox()
{
static long Linear12(int n) => 12L * n;
const int Max = VendorBuyMath.MaxAmount;
// Stock and money.
Eq(VendorBuyMath.MaxBuy(-1, -1, Linear12), Max, "unlimited stock, money unknown: the engine's limit");
Eq(VendorBuyMath.MaxBuy(0, 1000, Linear12), 0, "the vendor has none");
Eq(VendorBuyMath.MaxBuy(50, -1, Linear12), 50, "50 in stock, money unknown: 50");
Eq(VendorBuyMath.MaxBuy(-1, 1000, Linear12), 83, "12 each, 1,000 to spend: 83");
Eq(VendorBuyMath.MaxBuy(-1, 11, Linear12), 0, "12 each, 11 to spend: none");
Eq(VendorBuyMath.MaxBuy(-1, 12, Linear12), 1, "12 each, 12 to spend: one");
Eq(VendorBuyMath.MaxBuy(100, 1200, Linear12), 100, "exactly enough for the whole stock");
Eq(VendorBuyMath.MaxBuy(100, 1_000_000, Linear12), 100, "rich: the stock");
Eq(VendorBuyMath.MaxBuy(Max + 5, -1, Linear12), Max, "a stock past the limit is capped");
Eq(VendorBuyMath.MaxBuy(-1, 0, _ => 0), Max, "a free vendor (cost 0): the engine's limit");
Eq(VendorBuyMath.MaxBuy(-1, 100, _ => -1), 0, "a cost that overflowed to negative counts as too much");
// ACE's per-stack pricing (each created stack rounds up, floor 1): searched, not divided.
foreach (float rate in new[] { 1.15f, 0.9f, 2.5f })
foreach (int maxStack in new[] { 1, 7, 100 })
{
long StackCost(int n)
{
long full = n / maxStack, rem = n % maxStack;
return full * VendorRatePolicy.PlayerPaysForStack(rate, Misc, 3L * maxStack)
+ (rem > 0 ? VendorRatePolicy.PlayerPaysForStack(rate, Misc, 3L * rem) : 0);
}
foreach (long money in new long[] { 0, 1, 3, 4, 100, 345, 1000, 9999 })
{
int got = VendorBuyMath.MaxBuy(5000, money, StackCost);
bool fits = got == 0 || StackCost(got) <= money;
bool most = got == 5000 || StackCost(got + 1) > money;
Check(fits && most, $"rate {rate}, stacks of {maxStack}, {money} to spend: {got} is the most that fits");
}
}
// Where the number starts and how a typed one is kept.
Eq(VendorBuyMath.Prefill(50, 200), 50, "the toolbar's 50, 200 buyable: 50");
Eq(VendorBuyMath.Prefill(500, 200), 200, "the toolbar's 500, 200 buyable: 200");
Eq(VendorBuyMath.Prefill(1, 200), 1, "the toolbar's 1: 1");
Eq(VendorBuyMath.Prefill(0, 200), 1, "no toolbar number: 1");
Eq(VendorBuyMath.Prefill(-7, 200), 1, "a junk toolbar number: 1");
Eq(VendorBuyMath.Prefill(50, 0), 1, "nothing buyable: 1 (Buy is off)");
Eq(VendorBuyMath.Clamp(0, 10), 1, "typed 0: 1");
Eq(VendorBuyMath.Clamp(-3, 10), 1, "typed -3: 1");
Eq(VendorBuyMath.Clamp(11, 10), 10, "typed 11 of 10: 10");
Eq(VendorBuyMath.Clamp(7, 10), 7, "typed 7 of 10: 7");
Eq(VendorBuyMath.Clamp(7, 0), 1, "nothing buyable: 1");
Eq(VendorBuyMath.Half(0), 1, "half of 0: 1");
Eq(VendorBuyMath.Half(1), 1, "half of 1: 1");
Eq(VendorBuyMath.Half(9), 4, "half of 9: 4");
}
// The box and the split-globals fix must use what is tested here.
private static void BuyBoxWiringPinned()
{
string? box = FindUp(Path.Combine("src", "RynthCore.Engine", "ImGui", "Panels", "InventoryFace.VendorBuy.cs"));
Check(box != null, "found InventoryFace.VendorBuy.cs");
if (box != null)
{
string text = File.ReadAllText(box);
foreach (string needle in new[]
{
"VendorBuyMath.Prefill(toolbar, MaxBuy(snap, item))",
"VendorBuyMath.MaxBuy(item.Unlimited ? -1 : item.Amount, VendorTrade.MoneyFor(snap)",
"VendorBuyMath.Clamp(_buyAmount, max)",
"UiDropTargets.Publish(VendorDropKey, Title, origin, origin + size, snap != null, IsVendorItem)",
"VendorTrade.RequestBuy(_buyVendor, [_buyItem], [_buyAmount])",
})
Check(text.Contains(needle, StringComparison.Ordinal), "InventoryFace.VendorBuy.cs contains: " + needle);
}
string? hooks = FindUp(Path.Combine("src", "RynthCore.Engine", "Compatibility", "ClientHelperHooks.cs"));
Check(hooks != null, "found ClientHelperHooks.cs");
if (hooks != null)
{
string text = File.ReadAllText(hooks);
int reads = CountOf(text, "SplitGlobals keep = SplitGlobals.Read();");
int restores = CountOf(text, "keep.Restore();");
Check(reads == 2 && restores == 2, $"MoveItemInternal and SplitStackInternal both keep AC's split globals (reads {reads}, restores {restores})");
Check(!text.Contains("try { Marshal.WriteInt32(new IntPtr(_splitAmountAddr), 1); } catch { }", StringComparison.Ordinal),
"SplitStackInternal no longer leaves split_amount at 1 after it");
}
}
private static int CountOf(string text, string needle)
{
int n = 0;
for (int i = text.IndexOf(needle, StringComparison.Ordinal); i >= 0; i = text.IndexOf(needle, i + needle.Length, StringComparison.Ordinal)) n++;
return n;
}
private static string? FindUp(string relative)
{
for (DirectoryInfo? d = new(AppContext.BaseDirectory); d != null; d = d.Parent)