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 GalaxyCommodityOptionsWireSelfTest()
    {
        static JsonElement Parse(string json){using var d=JsonDocument.Parse(json);return d.RootElement.Clone();}
        lock(galaxyAccountMutex)lock(snapshotLock)
        {
            var savedFrame=snapshot;var savedInGame=inGame;var savedOptions=galaxyCommodityOptions;var savedVersion=galaxyCommodityOptionsVersion;
            try
            {
                uint passed=0;var now=GetTickCount64();inGame=true;snapshot=new(){valid=true,entity=42,tick=now};galaxyCommodityOptionsVersion=7;
                var rows=Enumerable.Range(0,18).Select(i=>new GalaxyCommodityOption(i==17?uint.MaxValue-1:0xF0000000u+(uint)i,
                    "Commodity"+i,i%2==0?"Metals":"",i%2==0?1:2,i%2==0?true:null)).ToArray();
                galaxyCommodityOptions=new(now,42,rows,3);
                JsonElement Read(string request)=>Parse(GalaxyCommodityOptionsDescription(Parse(request)).ToJsonString());
                var first=Read("{}");var second=Read("{\"generation\":7,\"offset\":16}");
                if(first.GetProperty("available").GetBoolean()&&!first.GetProperty("complete").GetBoolean()&&first.GetProperty("items").GetArrayLength()==16&&first.GetProperty("total").GetInt32()==18&&first.GetProperty("nextOffset").GetUInt64()==16)passed|=1;
                var item=second.GetProperty("items")[1];
                if(second.GetProperty("items").GetArrayLength()==2&&second.GetProperty("nextOffset").ValueKind==JsonValueKind.Null&&item.GetProperty("uid").GetUInt32()==uint.MaxValue-1&&item.GetProperty("name").GetString()=="Commodity17"&&
                   item.GetProperty("publisherEligible").ValueKind==JsonValueKind.Null&&item.GetProperty("kind").GetInt32()==2)passed|=2;
                item=first.GetProperty("items")[0];
                if(item.GetProperty("uid").GetUInt32()==0xF0000000&&item.GetProperty("publisherEligible").GetBoolean()&&first.GetProperty("unresolvedCount").GetInt32()==3&&
                   first.GetProperty("source").GetString()=="original-commodity-enumeration-and-definitions"&&first.GetProperty("entityId").GetString()=="42")passed|=4;
                var rejected=false;try{Read("{\"generation\":8}");}catch(InvalidOperationException){rejected=true;}if(rejected)passed|=8;
                snapshot.entity=43;var guarded=!Read("{}").GetProperty("available").GetBoolean();
                snapshot.entity=42;galaxyCommodityOptions=new(now-6001,42,rows,3);guarded&=!Read("{}").GetProperty("available").GetBoolean();
                galaxyCommodityOptions=new(now+1000,42,rows,3);guarded&=!Read("{}").GetProperty("available").GetBoolean();
                galaxyCommodityOptions=new(now,42,rows,3);inGame=false;guarded&=!Read("{}").GetProperty("available").GetBoolean();inGame=true;if(guarded)passed|=16;
                galaxyCommodityOptions=new(now,42,[],7);var empty=Read("{}");
                if(empty.GetProperty("available").GetBoolean()&&!empty.GetProperty("complete").GetBoolean()&&empty.GetProperty("items").GetArrayLength()==0&&empty.GetProperty("unresolvedCount").GetInt32()==7)passed|=32;
                var symbol="$Commodity_中_\"Quote\"_\\Slash";
                galaxyCommodityOptions=new(now,42,[new(0,symbol,"",1,true)],0);item=Read("{}").GetProperty("items")[0];
                if(item.GetProperty("uid").GetUInt32()==0&&item.GetProperty("name").GetString()==symbol&&item.GetProperty("category").GetString()=="")passed|=64;
                galaxyCommodityOptions=new(now,42,Enumerable.Range(0,40).Select(i=>new GalaxyCommodityOption((uint)i,new string('中',85),new string('中',85),1,true)).ToArray(),0);
                var bounded=Read("{\"limit\":9999}");
                if(bounded.GetProperty("items").GetArrayLength()==16&&System.Text.Encoding.UTF8.GetByteCount(bounded.GetRawText())<65535&&galaxyCommodityOptions.items.Length==40)passed|=128;
                return passed;
            }
            finally{snapshot=savedFrame;inGame=savedInGame;galaxyCommodityOptions=savedOptions;galaxyCommodityOptionsVersion=savedVersion;}
        }
    }
#if PLUGIN_NAVIGATION
    [UnmanagedCallersOnly(EntryPoint="XFENavigationGalaxyCommodityOptionsWireSelfTest")]
    internal static uint ExportGalaxyCommodityOptionsWireSelfTest()=>RunTest(GalaxyCommodityOptionsWireSelfTest);
#endif
}