namespace XFEEDToolBox.Plugin; internal static unsafe partial class Navigation { static GalaxyCurrentTradeFlows? galaxyCurrentTradeFlows; static ulong galaxyCurrentTradeFlowsVersion; static void PollGalaxyCurrentTradeFlows(Snapshot frame) { if(!TryReadGalaxyCurrentTradeFlows(frame,out var observed))return; lock(galaxyAccountMutex) { if(galaxyCurrentTradeFlows is not {} old||old.entity!=observed.entity||old.revision!=observed.revision|| old.lifetimeSeconds!=observed.lifetimeSeconds||old.refreshSeconds!=observed.refreshSeconds|| observed.originalClockmaximum) throw new ArgumentException("Invalid current trade flow parameter: "+key); return number; } var offset=Parameter(request,"offset",0,0,65536); var limit=Parameter(request,"limit",16,1,16); var generation=Parameter(request,"generation",0,1,ulong.MaxValue); if(offset>0&&generation==0)throw new ArgumentException("Current trade flow pagination requires its generation"); lock(galaxyAccountMutex) { if(generation>0&&generation!=galaxyCurrentTradeFlowsVersion)throw new InvalidOperationException("Current trade flow snapshot changed"); var frame=Current();var observed=galaxyCurrentTradeFlows;var now=GetTickCount64(); var available=inGame&&frame.valid&&observed is not null&&observed.entity==frame.entity&&now>=observed.tick&&now-observed.tick<=6000; var rows=available?observed!.items:[]; if(available&&offset>(ulong)rows.Length)throw new ArgumentException("Current trade flow offset exceeds its snapshot"); var items=new JsonArray();var wireBytes=0; for(var i=offset;i<(ulong)rows.Length&&i-offset48000)throw new InvalidOperationException("Original current trade flow exceeds the wire bound"); if(items.Count>0&&wireBytes+bytes>48000)break; wireBytes+=bytes;items.Add((JsonNode)item); } return Obj(("available",available),("generation",galaxyCurrentTradeFlowsVersion),("offset",offset),("total",rows.Length),("items",items), ("nextOffset",offset+(ulong)items.Count<(ulong)rows.Length?JsonValue.Create(offset+(ulong)items.Count):null), ("complete",false),("source","original-current-trade-flow-cache"),("entityId",available?observed!.entity.ToString():""), ("originalClock",available?observed!.originalClock.ToString():null), ("lifetimeSeconds",available?JsonValue.Create(observed!.lifetimeSeconds):null),("refreshSeconds",available?JsonValue.Create(observed!.refreshSeconds):null), ("revision",available?JsonValue.Create(observed!.revision):null),("unresolvedCount",available?JsonValue.Create(observed!.unresolvedCount):null)); } } }