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

XFEEDToolBox

【WinUI】XFE精英危险工具箱

公开
关注 0 Fork 0 Star 0
UTF-8
namespace XFEEDToolBox.Plugin;

internal static unsafe partial class Navigation
{
    // Original3AF6C40 ->1418810: centre metadata state0 returns extent0;
    // otherwise actual ownerIndex ->260B definition ->1A0+state*10hex+8.
    // It is independent of the Activities predicate radius(service+3E8).
    // The original150 lookup writes a last-key cache; this port only reads.
    static bool CopyGalaxyPowerOuterExtent(GalaxyPowerOuterContext context,out float? extent)
    {
        extent=null;
        try
        {
            if(!GalaxyPowerOuterSource(context)||!GalaxyPowerActivityFind(context.service+0x3C0,
                context.centreSystemAddress,-1,0x180,16,out var node))return false;
            if(node==0)return true; // Unobserved centre metadata stays unknown.
            var metadata=node+0x10;var ownerIndex=Read<ulong>(metadata);var state=Read<int>(metadata+0xC);
            if(state is <0 or >4)return true;
            float value;var vector=(nuint)0;var count=0UL;var definition=(nuint)0;
            if(state==0)value=0;
            else
            {
                if(!CopyGalaxyPowerOptions(context.service-0x58,context.owner,context.expectedImage,out var options))return false;
                count=Read<ulong>(context.service+0x330);vector=Pointer(context.service+0x338);
                if(count!=(ulong)options.Length||ownerIndex>=count||vector<0x10000)return true;
                definition=vector+(nuint)ownerIndex*0x260;
                value=Read<float>(definition+0x1A8+(nuint)state*0x10);
                if(!float.IsFinite(value)||value is <0 or >1000000)return true;
            }
            if(!GalaxyPowerOuterSource(context)||Read<ulong>(node)!=context.centreSystemAddress||
                Read<ulong>(metadata)!=ownerIndex||Read<int>(metadata+0xC)!=state||
                !GalaxyPowerActivityFind(context.service+0x3C0,context.centreSystemAddress,-1,0x180,16,out var checkedNode)||checkedNode!=node||
                state!=0&&(Read<ulong>(context.service+0x330)!=count||Pointer(context.service+0x338)!=vector||
                    Read<float>(definition+0x1A8+(nuint)state*0x10)!=value))return false;
            extent=value;return true;
        }
        catch{return false;}
    }

    static bool TryReadGalaxyPowerOuterExtent(GalaxyPowerOuterContext context,out float? extent)
    {
        extent=null;
        if(!Enabled()||!inGame||context.thread==0||context.thread!=owningThread||GetCurrentThreadId()!=context.thread||
            GetTickCount64()-context.tick>500||context.expectedImage!=image)return false;
        var frame=Current();
        return frame.valid&&frame.entity==context.entity&&(frame.referenceWorld&0x007FFFFFFFFFFFFFUL)==context.currentSystem&&
            CopyGalaxyPowerOuterExtent(context,out extent);
    }
}