XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEEDToolBox

【WinUI】XFE精英危险工具箱

公开
关注 0 Fork 0 Star 0
UTF-8
using System.Runtime.InteropServices;
using System.Text.Json;

namespace XFEEDToolBox.Plugin;

internal static unsafe partial class Navigation
{
    static uint GalaxyBasicSystemFactsWireSelfTest()
    {
        static JsonElement Parse(string text){using var document=JsonDocument.Parse(text);return document.RootElement.Clone();}
        lock(galaxyFactsMutex)
        {
            var saved=galaxyFactsWork;var generation=galaxyFactsGeneration;
            try
            {
                galaxyFactsWork=new();galaxyFactsGeneration=0;uint passed=0;
                JsonElement Wire(string op,string body)=>Parse(GalaxyFilterFactsRequest(op,Parse(body)).ToJsonString());
                void Cancel()=>Wire("galaxy.facts.cancel","{\"generation\":"+galaxyFactsWork.generation+"}");
                Wire("galaxy.facts","{\"systemAddresses\":[\"9007199254740995\"]}");
                galaxyFactsWork.items.Add((9007199254740995UL,default));galaxyFactsWork.basicSystems[9007199254740995UL]=new(1,4,4,6,17,1,79);
                if(!galaxyFactsWork.includeBasicSystem&&Wire("galaxy.facts.result","{\"generation\":1}").GetProperty("items")[0].GetProperty("basicSystem").ValueKind==JsonValueKind.Null)passed|=1;
                Cancel();Wire("galaxy.facts","{\"systemAddresses\":[\"9007199254740995\"],\"includeBasicSystem\":true}");
                galaxyFactsWork.items.Add((9007199254740995UL,default));
                if(galaxyFactsWork.includeBasicSystem&&Wire("galaxy.facts.result","{\"generation\":2}").GetProperty("items")[0].GetProperty("basicSystem").ValueKind==JsonValueKind.Null)passed|=2;
                galaxyFactsWork.basicSystems[9007199254740995UL]=new(9007199254740999UL,4,4,6,17,9007199254740997UL,79){allegianceKey="Federation"};
                var basic=Wire("galaxy.facts.result","{\"generation\":2}").GetProperty("items")[0].GetProperty("basicSystem");
                if(basic.GetProperty("population").GetString()=="9007199254740999"&&basic.GetProperty("allegianceId").GetString()=="9007199254740997"&&
                   basic.GetProperty("governmentId").GetUInt32()==4&&basic.GetProperty("primaryEconomyId").GetUInt32()==4&&
                   basic.GetProperty("secondaryEconomyId").GetUInt32()==6&&basic.GetProperty("factionStateId").GetUInt32()==17&&basic.GetProperty("securityValue").GetByte()==79&&
                   basic.GetProperty("allegianceKey").GetString()=="Federation")passed|=4;
                var observed=!basic.GetProperty("defaulted").GetBoolean();
                galaxyFactsWork.basicSystems[9007199254740995UL]=new(0,1,1,1,0,ulong.MaxValue,0){defaulted=true,allegianceKey="None"};
                basic=Wire("galaxy.facts.result","{\"generation\":2}").GetProperty("items")[0].GetProperty("basicSystem");
                var originalDefault=basic.GetProperty("defaulted").GetBoolean()&&basic.GetProperty("population").GetString()=="0"&&basic.GetProperty("allegianceKey").GetString()=="None";
                galaxyFactsWork.basicSystems[9007199254740995UL]=new(0,uint.MaxValue,29,28,40,ulong.MaxValue,255);
                basic=Wire("galaxy.facts.result","{\"generation\":2}").GetProperty("items")[0].GetProperty("basicSystem");
                if(basic.GetProperty("population").GetString()=="0"&&basic.GetProperty("allegianceId").GetString()=="18446744073709551615"&&
                   basic.GetProperty("governmentId").GetUInt32()==uint.MaxValue&&basic.GetProperty("primaryEconomyId").GetUInt32()==29&&basic.GetProperty("securityValue").GetUInt32()==255&&
                   basic.GetProperty("allegianceKey").ValueKind==JsonValueKind.Null&&observed&&originalDefault&&!basic.GetProperty("defaulted").GetBoolean())passed|=8;
                var rejected=0;foreach(var value in new[]{"1","\"true\"","{}","[]"})
                    try{Wire("galaxy.facts","{\"systemAddresses\":[\"300\"],\"includeBasicSystem\":"+value+"}");}catch(InvalidDataException){rejected++;}
                if(rejected==4&&galaxyFactsGeneration==2)passed|=16;
                Cancel();var previous=galaxyFactsWork;
                Wire("galaxy.facts","{\"systemAddresses\":[\"300\"],\"includeBasicSystem\":false}");
                if(previous.cancelled&&previous.done&&!galaxyFactsWork.includeBasicSystem&&galaxyFactsWork.basicSystems.Count==0)passed|=32;
                Cancel();Wire("galaxy.facts","{\"systemAddresses\":[\"300\"],\"includeBasicSystem\":true}");
                galaxyFactsWork.items=Enumerable.Range(1,200).Select(i=>((ulong)i,default(GalaxyFilterFacts))).ToList();
                foreach(var (address,_) in galaxyFactsWork.items)galaxyFactsWork.basicSystems[address]=new(ulong.MaxValue,uint.MaxValue,uint.MaxValue,uint.MaxValue,uint.MaxValue,ulong.MaxValue,255);
                var page=Wire("galaxy.facts.result","{\"generation\":4,\"limit\":9999}").GetProperty("items");
                if(page.GetArrayLength() is >0 and <=96&&page.EnumerateArray().Sum(row=>System.Text.Encoding.UTF8.GetByteCount(row.GetRawText()))<=48000)passed|=64;
                var frame=new Snapshot{valid=true,entity=42,referenceWorld=100};var work=new GalaxyFilterFactsWork{expires=100,includeBasicSystem=true};
                var bound=BindGalaxyFilterFactsWork(work,frame,1);frame.referenceWorld=101;
                if(bound&&!BindGalaxyFilterFactsWork(work,frame,2)&&work.done&&work.error.Contains("changed"))passed|=128;
                return passed;
            }
            finally{galaxyFactsWork=saved;galaxyFactsGeneration=generation;}
        }
    }
#if PLUGIN_NAVIGATION
    [UnmanagedCallersOnly(EntryPoint="XFENavigationGalaxyBasicSystemFactsWireSelfTest")]
    internal static uint ExportGalaxyBasicSystemFactsWireSelfTest()=>RunTest(GalaxyBasicSystemFactsWireSelfTest);
#endif
}