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
{
    static double HeatDisplayScale(double range,double moduleFraction,double hullFraction)
    {
        if(!double.IsFinite(range)||!double.IsFinite(moduleFraction)||!double.IsFinite(hullFraction)||range<=0||moduleFraction<=0||moduleFraction>=hullFraction||hullFraction>1)return 0;
        var scale=range*moduleFraction;
        return scale>=.5&&scale<=4?scale:0;
    }
    static double ReadHeatDisplayScale()=>HeatDisplayScale(Read<float>(image+0x51DAF1C),Read<float>(image+0x5324D78),Read<float>(image+0x5324D7C));
    static double HeatHudPercent(double internalPercent,double scale)=>scale>0&&double.IsFinite(internalPercent)?internalPercent/scale:double.NaN;
    static double HeatHudPercent(Snapshot frame)=>HeatHudPercent(frame.heatPercent,frame.heatDisplayScale);
    internal static uint HeatNormalizationSelfTest()
    {
        uint passed=0;var scale=HeatDisplayScale(3.5,3.0/7,5.0/7);
        if(Math.Abs(scale-1.5)<1e-12)passed|=1;
        if(Math.Abs(HeatHudPercent(73,scale)-48.6666666667)<1e-8&&(int)(HeatHudPercent(73,scale)+.5)==49)passed|=2;
        if(Math.Abs(HeatHudPercent(150,scale)-100)<1e-10&&HeatHudPercent(142.5,scale)==95)passed|=4;
        if(HeatDisplayScale(0,.5,.9)==0&&HeatDisplayScale(3.5,.9,.5)==0&&HeatDisplayScale(double.NaN,.5,.9)==0&&!double.IsFinite(HeatHudPercent(73,0)))passed|=8;
        var same=true;
        foreach(var initial in new[]{60d,100,140})
        {
            var raw=initial;var hud=initial/scale;
            for(var i=0;i<200;i++)
            {
                var r=Math.Clamp(raw/100,0,1);var h=Math.Clamp(hud/(100/scale),0,1);
                raw+=(80-67.15*r*r)*100/334*.05;
                hud+=(80-67.15*h*h)*100/(334*scale)*.05;
            }
            if(Math.Abs(raw/scale-hud)>1e-8)same=false;
        }
        if(same)passed|=16;return passed;
    }
}