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 GalaxyAccountWireSelfTest()
    {
        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 savedBookmarks=galaxyAccountBookmarks;var savedVersion=galaxyAccountVersion;
            try
            {
                uint passed=0;var now=GetTickCount64();inGame=true;snapshot=new(){valid=true,entity=42,tick=now};galaxyAccountVersion=7;
                var rows=Enumerable.Range(0,17).Select(i=>new GalaxyAccountBookmark((ulong)i,9007199254740995UL+(ulong)i,0,-1,"Private","System","","",0,0,false,false,false,i%2+1)).ToArray();
                galaxyAccountBookmarks=new(now,42,rows);
                JsonElement Read(string request)=>Request(GalaxyAccountDescription(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;
                if(page.GetProperty("items").GetArrayLength()==1&&page.GetProperty("items")[0].GetProperty("systemAddress").GetString()=="9007199254741011")passed|=2;
                var rejected=false;try{Read("{\"generation\":8}");}catch(InvalidOperationException){rejected=true;}if(rejected)passed|=4;
                snapshot.entity=43;if(!Read("{}").GetProperty("available").GetBoolean()&&Read("{}").GetProperty("items").GetArrayLength()==0)passed|=8;
                snapshot.entity=42;galaxyAccountBookmarks=new(now-6001,42,rows);if(!Read("{}").GetProperty("available").GetBoolean())passed|=16;
                // Escaping may expand short original strings on the wire. The
                // server must paginate by actual UTF-8 size as well as row count.
                var longName=new string('\u0001',512);
                galaxyAccountBookmarks=new(now,42,rows.Select(b=>b with{name=longName,systemName=longName,bodyName=longName,stationName=longName}).ToArray());
                var bounded=GalaxyAccountDescription(Request("{}"));var encoded=System.Text.Encoding.UTF8.GetByteCount(bounded.ToJsonString());
                if(encoded<65535&&bounded["items"]!.AsArray().Count is >0 and <16)passed|=32;
                return passed;
            }
            finally{snapshot=savedFrame;inGame=savedInGame;galaxyAccountBookmarks=savedBookmarks;galaxyAccountVersion=savedVersion;}
        }
    }
#if PLUGIN_NAVIGATION
    [UnmanagedCallersOnly(EntryPoint="XFENavigationGalaxyAccountWireSelfTest")]
    internal static uint ExportGalaxyAccountWireSelfTest()=>RunTest(GalaxyAccountWireSelfTest);
#endif
}