using System.Runtime.InteropServices; using System.Text.Json; namespace XFEEDToolBox.Plugin; internal static unsafe partial class Navigation { static uint GalaxyAccountMissionsWireSelfTest() { static JsonElement Request(string text){using var d=JsonDocument.Parse(text);return d.RootElement.Clone();} lock(galaxyAccountMutex)lock(snapshotLock) { var savedFrame=snapshot;var savedInGame=inGame;var savedMissions=galaxyAccountMissions;var savedVersion=galaxyMissionsVersion; try { uint passed=0;var now=GetTickCount64();inGame=true;snapshot=new(){valid=true,entity=42,tick=now};galaxyMissionsVersion=7; const ulong address=9007199254740993UL; var rows=Enumerable.Range(0,17).Select(i=>new GalaxyAccountMissionItem(i==16?ulong.MaxValue:(ulong)i,[address,address+1,address],address){markerType=i==16?45:4}).ToArray(); galaxyAccountMissions=new(now,42,rows); JsonElement Read(string request)=>Request(GalaxyMissionsDescription(Request(request)).ToJsonString()); var first=Read("{}");var page=Read("{\"generation\":7,\"offset\":16}"); if(first.GetProperty("available").GetBoolean()&&!first.GetProperty("complete").GetBoolean()&&first.GetProperty("items").GetArrayLength()==16)passed|=1; var item=page.GetProperty("items")[0]; if(page.GetProperty("items").GetArrayLength()==1&&item.GetProperty("missionId").GetString()==ulong.MaxValue.ToString()&&item.GetProperty("selectedSystemAddress").GetString()==address.ToString()&&item.GetProperty("systemAddresses").GetArrayLength()==3)passed|=2; if(item.GetProperty("markerType").GetInt32()==45&&first.GetProperty("items")[0].GetProperty("missionId").GetString()=="0")passed|=4; var rejected=false;try{Read("{\"generation\":8}");}catch(InvalidOperationException){rejected=true;}if(rejected)passed|=8; var copied=rows.Select(m=>m with{systemAddresses=(ulong[])m.systemAddresses.Clone()}).ToArray(); if(SameGalaxyMissions(rows,copied)&&!SameGalaxyMissions(rows,copied.Select((m,i)=>i==0?m with{markerType=45}:m).ToArray()))passed|=16; snapshot.entity=43;var other=Read("{}");var guarded=!other.GetProperty("available").GetBoolean()&&other.GetProperty("items").GetArrayLength()==0; snapshot.entity=42;galaxyAccountMissions=new(now-6001,42,rows);guarded&=!Read("{}").GetProperty("available").GetBoolean(); galaxyAccountMissions=new(now,42,rows);inGame=false;guarded&=!Read("{}").GetProperty("available").GetBoolean();inGame=true;if(guarded)passed|=32; var large=Enumerable.Repeat(address,2000).ToArray();galaxyAccountMissions=new(now,42,[new(1,large,address),new(2,large,address)]); var bounded=Read("{}"); if(bounded.GetProperty("items").GetArrayLength()==1&&bounded.GetProperty("items")[0].GetProperty("systemAddresses").GetArrayLength()==2000&&System.Text.Encoding.UTF8.GetByteCount(bounded.GetRawText())<65535)passed|=64; galaxyAccountMissions=new(now,42,[new(1,Enumerable.Repeat(address,4096).ToArray(),address)]); rejected=false;try{Read("{}");}catch(InvalidOperationException){rejected=true;}if(rejected&&galaxyAccountMissions.items[0].systemAddresses.Length==4096)passed|=128; return passed; } finally{snapshot=savedFrame;inGame=savedInGame;galaxyAccountMissions=savedMissions;galaxyMissionsVersion=savedVersion;} } } #if PLUGIN_NAVIGATION [UnmanagedCallersOnly(EntryPoint="XFENavigationGalaxyAccountMissionsWireSelfTest")] internal static uint ExportGalaxyAccountMissionsWireSelfTest()=>RunTest(GalaxyAccountMissionsWireSelfTest); #endif }