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 GalaxyPowerStatusWireSelfTest()
    {
        static JsonElement Parse(string json){using var d=JsonDocument.Parse(json);return d.RootElement.Clone();}
        lock(galaxyFactsMutex)
        {
            var savedWork=galaxyFactsWork;var savedGeneration=galaxyFactsGeneration;
            try
            {
                uint passed=0;galaxyFactsWork=new();galaxyFactsGeneration=0;
                JsonElement Wire(string op,string fields)=>Parse(GalaxyFilterFactsRequest(op,Parse("{"+fields+"}")).ToJsonString());
                JsonElement Page()=>Wire("galaxy.facts.result","\"generation\":"+galaxyFactsWork.generation);
                void Cancel()=>Wire("galaxy.facts.cancel","\"generation\":"+galaxyFactsWork.generation);
                Wire("galaxy.facts","\"systemAddresses\":[\"300\"],\"includePowerStatus\":true");
                galaxyFactsWork.items.Add((300,default));var row=Page().GetProperty("items")[0];var status=row.GetProperty("powerStatus");
                if(status.EnumerateObject().Count()==7&&status.EnumerateObject().All(p=>p.Value.ValueKind==JsonValueKind.Null)&&
                   !galaxyFactsWork.includePowerTerritory&&!galaxyFactsWork.includePowerActivity)passed|=1;
                galaxyFactsWork.powerStatus[300]=new(0,3,null,null,uint.MaxValue,0x80000001,false);
                status=Page().GetProperty("items")[0].GetProperty("powerStatus");
                if(status.GetProperty("rawState").GetInt32()==0&&status.GetProperty("stateIndex").GetInt32()==3&&
                   status.GetProperty("ownerIndex").ValueKind==JsonValueKind.Null&&status.GetProperty("unoccupiedPowerFlags").GetUInt32()==uint.MaxValue&&
                   status.GetProperty("contestPowerFlags").GetUInt32()==0x80000001&&!status.GetProperty("generalAdmissible").GetBoolean())passed|=2;
                galaxyFactsWork.powerStatus[300]=new(3,7,74,17,0,0,null);
                status=Page().GetProperty("items")[0].GetProperty("powerStatus");
                if(status.GetProperty("ownerIndex").GetInt32()==74&&status.GetProperty("ownerInternalPowerId").GetInt32()==17&&
                   status.GetProperty("generalAdmissible").ValueKind==JsonValueKind.Null)passed|=4;
                Cancel();Wire("galaxy.facts","\"systemAddresses\":[\"300\"]");galaxyFactsWork.items.Add((300,default));
                if(Page().GetProperty("items")[0].GetProperty("powerStatus").ValueKind==JsonValueKind.Null&&galaxyFactsWork.powerStatus.Count==0)passed|=8;
                Cancel();var generation=galaxyFactsGeneration;var rejected=false;
                try{Wire("galaxy.facts","\"systemAddresses\":[\"300\"],\"includePowerStatus\":1");}catch(InvalidDataException){rejected=true;}
                if(rejected&&galaxyFactsGeneration==generation)passed|=16;
                Wire("galaxy.facts","\"systemAddresses\":[\"301\"],\"includePowerStatus\":true");var retired=galaxyFactsWork;Cancel();
                Wire("galaxy.facts","\"systemAddresses\":[\"302\"],\"includePowerStatus\":true");
                rejected=false;try{Wire("galaxy.facts.result","\"generation\":"+retired.generation);}catch(InvalidOperationException){rejected=true;}
                if(retired.cancelled&&retired.done&&rejected&&galaxyFactsWork.powerStatus.Count==0)passed|=32;
                var work=galaxyFactsWork;work.includePowerActivity=true;work.powerAllPowers=true;work.powerActivityId=5;
                work.includePowerTerritory=true;work.territoryActivityEnabled=true;work.includePowerOuter=true;work.done=true;
                for(ulong i=1;i<=180;i++)
                {
                    work.items.Add((9007199254740992+i,default));var id=9007199254740992+i;
                    work.powerStatus[id]=new(2,5,1,17,uint.MaxValue,uint.MaxValue,true);
                    work.powerTerritory[id]=new(2,5,17,29.8375f,[.4f,.5f,1.5f],[.13286832f,.21404114f,2.5371552f],.15f);
                    work.powerOuter[id]=new(false,id,[12345.6789,-23456.789,34567.89],1000000);
                    work.powerCounters[id]=2.5f;
                }
                var first=Page();var count=first.GetProperty("items").GetArrayLength();
                if(count is >0 and <96&&System.Text.Encoding.UTF8.GetByteCount(first.GetRawText())<65535&&first.GetProperty("total").GetInt32()==180)passed|=64;
                var addresses=new List<ulong>();var bounded=true;
                while(addresses.Count<180)
                {
                    var page=Wire("galaxy.facts.result","\"generation\":"+work.generation+",\"offset\":"+addresses.Count+",\"limit\":96");
                    var rows=page.GetProperty("items");if(rows.GetArrayLength()==0){bounded=false;break;}
                    bounded&=System.Text.Encoding.UTF8.GetByteCount(page.GetRawText())<65535;
                    addresses.AddRange(rows.EnumerateArray().Select(r=>ulong.Parse(r.GetProperty("systemAddress").GetString()!)));
                }
                if(bounded&&addresses.SequenceEqual(Enumerable.Range(1,180).Select(i=>9007199254740992UL+(ulong)i)))passed|=128;
                return passed;
            }
            finally{galaxyFactsWork=savedWork;galaxyFactsGeneration=savedGeneration;}
        }
    }
#if PLUGIN_NAVIGATION
    [UnmanagedCallersOnly(EntryPoint="XFENavigationGalaxyPowerStatusWireSelfTest")]
    internal static uint ExportGalaxyPowerStatusWireSelfTest()=>RunTest(GalaxyPowerStatusWireSelfTest);
#endif
}