diff options
| author | Valentin Popov <valentin@popov.link> | 2026-12-01 12:11:27 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-12-01 12:11:27 +0300 |
| commit | fac74ba2d2487cb500d24de4223a0ffec50fa580 (patch) | |
| tree | fcc13a4bb05b1a9a4fa7ea29f0fae5477e469f8c /crates/fparkan-script/tests/handler2_native_oracle.cs | |
| parent | 21b13ca1493d6f4d2da2add874f3fcd29b3cf5fe (diff) | |
| download | fparkan-fac74ba2d2487cb500d24de4223a0ffec50fa580.tar.xz fparkan-fac74ba2d2487cb500d24de4223a0ffec50fa580.zip | |
fix(ai): preserve clan job priorities through factory dispatch
Match GOG ai.dll when refreshing the same request and starting equally weighted jobs. Resolve generated factory IDs when dispatching or awaiting production.
Verified from stock starts in Two Fortresses and Third Part. Two Fortresses uses a newly built factory for a combat robot. The small factory in Third Part still lacks a compatible prepared design. The armed stock replay reached late cleanup and left a transport to pursue.
Diffstat (limited to 'crates/fparkan-script/tests/handler2_native_oracle.cs')
| -rw-r--r-- | crates/fparkan-script/tests/handler2_native_oracle.cs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/crates/fparkan-script/tests/handler2_native_oracle.cs b/crates/fparkan-script/tests/handler2_native_oracle.cs index f632c688..52e9456b 100644 --- a/crates/fparkan-script/tests/handler2_native_oracle.cs +++ b/crates/fparkan-script/tests/handler2_native_oracle.cs @@ -7,6 +7,7 @@ using System.Text; internal static class Handler2NativeOracle { private const uint LoadWithAlteredSearchPath = 0x00000008; private const int RefreshRecordRva = 0x5070; + private const int SubmitRva = 0x59f0; private const string ExpectedSha256 = "c19cd6cd31cd2896f8c4ba0f0e700dd3408aec8182daaf4863d98a7d233a2abc"; [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] @@ -18,6 +19,10 @@ internal static class Handler2NativeOracle { [UnmanagedFunctionPointer(CallingConvention.ThisCall)] private delegate void RefreshRecord(IntPtr record); + [UnmanagedFunctionPointer(CallingConvention.ThisCall)] + private delegate void SubmitRecord(IntPtr queue, int kind, float priority, uint increment, + uint sender, uint first, uint second, uint third, IntPtr name); + private static int Main() { if (IntPtr.Size != 4) { Console.Error.WriteLine("Build this oracle with an x86 target; ai.dll is 32-bit."); @@ -66,11 +71,56 @@ internal static class Handler2NativeOracle { AssertRefresh(refresh, record, UInt32.MaxValue - 2); } finally { Marshal.FreeHGlobal(record); } + + var submit = (SubmitRecord)Marshal.GetDelegateForFunctionPointer( + IntPtr.Add(module, SubmitRva), typeof(SubmitRecord)); + AssertMatchingSubmission(submit, 0.55011004f, 0.545f, false); + AssertMatchingSubmission(submit, 0.545f, 0.55011004f, true); + AssertMatchingSubmission(submit, 1.0f, 1.0f, true); + AssertMatchingSubmission(submit, -0.0f, 0.0f, true); + AssertMatchingSubmission(submit, Single.NaN, 1.0f, false); + AssertMatchingSubmission(submit, 1.0f, Single.NaN, false); } finally { FreeLibrary(module); } return 0; } + private static void AssertMatchingSubmission(SubmitRecord submit, float before, float incoming, + bool expectedRefresh) { + IntPtr queue = Marshal.AllocHGlobal(0x380); + IntPtr record = Marshal.AllocHGlobal(100); + try { + Marshal.Copy(new byte[0x380], 0, queue, 0x380); + Marshal.Copy(new byte[100], 0, record, 100); + Marshal.WriteInt32(queue, 0x28, 1); + Marshal.WriteIntPtr(queue, 0x30, record); + Marshal.WriteInt32(record, 0, 3); + Marshal.WriteInt32(record, 4, unchecked((int)0x80000010)); + Marshal.WriteInt32(record, 0xc, 91); + Marshal.WriteInt32(record, 0x14, Bits(before)); + Marshal.WriteInt32(record, 0x24, 7); + Marshal.WriteInt32(record, 0x28, 4); + submit(queue, 3, incoming, 99, 0, 0x80000010, 0, 92, IntPtr.Zero); + int counter = Marshal.ReadInt32(record, 0x24); + Console.WriteLine("stored={0:R} submitted={1:R} counter={2}", before, incoming, counter); + if (Marshal.ReadInt32(queue, 0x28) != 1 || + Marshal.ReadInt32(record, 0x14) != Bits(expectedRefresh ? incoming : before) || + counter != (expectedRefresh ? 11 : 7) || + Marshal.ReadInt32(record, 0xc) != (expectedRefresh ? 92 : 91) || + Marshal.ReadInt32(record, 0x28) != 4) { + throw new InvalidOperationException("Unexpected matching submission result."); + } + } + finally { + Marshal.FreeHGlobal(record); + Marshal.FreeHGlobal(queue); + } + } + + private static int Bits(float value) { + return BitConverter.ToInt32(BitConverter.GetBytes(value), 0); + } + private static void AssertRefresh(RefreshRecord refresh, IntPtr record, uint expectedCounter) { uint savedIncrement = unchecked((uint)Marshal.ReadInt32(record, 0x28)); refresh(record); |
