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

XFEEDToolBox

【WinUI】XFE精英危险工具箱

公开
关注 0 Fork 0 Star 0
UTF-8
using System.Buffers.Binary;

namespace XFEEDToolBox.Plugin;

internal static unsafe partial class Navigation
{
    internal sealed record GalaxyAccountCommunityGoals(ulong tick,ulong entity,ulong[] systemAddresses)
    {
        // This is the original map's published system list. No evidence proves
        // that an empty list is a complete current account/goal-board answer.
        internal bool complete=>false;
        internal string source=>"original-community-goal-map-published-cache";
    }

    static bool GalaxyCommunityGoalSource(nuint manager,nuint owner,nuint expectedImage)
        =>manager>=0x10000&&owner>=0x10000&&Pointer(manager)==expectedImage+0x55276B8&&
            Pointer(manager+8)==expectedImage+0x55276E8&&Pointer(manager+0x60)==expectedImage+0x5527810&&
            Pointer(manager+0x10)==owner;

    // Pinned6891 map3AFF080 enumerates interface+18 for setting16 and passes
    // each ulong address to3B8C0C0 with original marker type7 CommunityGoal.
    // Type5FA10F0 is registered at manager+60 by3A5E710; ctor3A0E740
    // installs this interface. Getter11D3BF0 returns iface+1B8=manager+218.
    // ED5A type/getter/VT compatibility is independently recorded in
    // thargoid-account-sources/cg-shared-interface-compatibility.json.
    static bool CopyGalaxyCommunityGoals(nuint manager,nuint owner,nuint expectedImage,out ulong[] systemAddresses)
    {
        systemAddresses=[];
        try
        {
            if(!GalaxyCommunityGoalSource(manager,owner,expectedImage))return false;
            var header=Platform.ReadBytes(manager+0x218,0x20);
            var capacity=BinaryPrimitives.ReadUInt64LittleEndian(header);
            var count=BinaryPrimitives.ReadUInt64LittleEndian(header.AsSpan(0x10));
            var vector=(nuint)BinaryPrimitives.ReadUInt64LittleEndian(header.AsSpan(0x18));
            if(count>4096||capacity>65536||count>capacity||count!=0&&vector<0x10000)return false;
            var bytes=count==0?[]:Platform.ReadBytes(vector,checked((int)count*8));
            var addresses=new ulong[(int)count];
            for(var index=0;index<addresses.Length;index++)
            {
                var address=BinaryPrimitives.ReadUInt64LittleEndian(bytes.AsSpan(index*8));
                if(address==0||address>=0x80000000000000UL)return false;
                // Preserve the original order and duplicates. A system can
                // host multiple community goals; no synthetic goal ID exists.
                addresses[index]=address;
            }
            if(!GalaxyCommunityGoalSource(manager,owner,expectedImage)||
               !Platform.ReadBytes(manager+0x218,0x20).AsSpan().SequenceEqual(header)||
               count!=0&&!Platform.ReadBytes(vector,bytes.Length).AsSpan().SequenceEqual(bytes))return false;
            systemAddresses=addresses;return true;
        }
        catch{return false;}
    }

    static bool TryReadGalaxyAccountCommunityGoals(Snapshot frame,out GalaxyAccountCommunityGoals result)
    {
        result=new(0,0,[]);
        if(!Enabled()||!inGame||!frame.valid||frame.physics==0||owningThread==0||GetCurrentThreadId()!=owningThread)return false;
        try
        {
            if(!TryGetGalaxyAccountRegistry(frame,out var registry))return false;
            var type=Read<uint>(image+0x5FA10F0);var component=RegisteredComponent(registry,type);
            if(component<0x10060||Pointer(component)!=image+0x5527810)return false;
            var manager=component-0x60;var owner=Pointer(manager+0x10);
            if(!CopyGalaxyCommunityGoals(manager,owner,image,out var systems)||
               !TryGetGalaxyAccountRegistry(frame,out var confirmedRegistry)||confirmedRegistry!=registry||
               RegisteredComponent(registry,type)!=component||Current().entity!=frame.entity)return false;
            result=new(frame.tick,frame.entity,systems);return true;
        }
        catch{return false;}
    }
}