using System.Numerics; namespace XFEEDToolBox.Plugin; internal static unsafe partial class Navigation { internal sealed record GalaxyPowerOuterStyleFact(float[] rawRgb,float[] linearRgb,float size,float opacity); internal sealed class GalaxyPowerOuterStyleContext { internal GalaxyPowerOuterContext outer=new(); internal nuint vector; internal GalaxyPowerOption[] options=[]; } // Pinned 6891 source3ACF250 +3B2F080 +3B264B0. Configuration // (286,6144)+F8/104/110 holds LINEAR (.4,.4,.4), (1,1,1), // (1,1,1); ctor3AC40B0(mode0) stores the inverse transfer in dual+0C. // Point getter3B28160 simply returns object64 = resource default .7. // No selected Power, recent counter or camera-distance term enters it. static float GalaxyPowerOuterRawColour(float value) { const float gamma=2.4f,offset=.055f; var denominator=gamma-1; var pivot=MathF.Pow(offset*gamma/(denominator*(1+offset)),gamma); var slope=(denominator/offset)*pivot; return value(outer.expectedImage+0x5FDB275)!=0|| !CopyGalaxyPowerOptions(outer.service-0x58,outer.owner,outer.expectedImage,out var options))return false; result=new(){outer=outer,vector=Pointer(outer.service+0x338),options=options}; return GalaxyPowerOuterStyleStable(result); } catch{return false;} } static bool GalaxyPowerOuterStyleStable(GalaxyPowerOuterStyleContext context) { try { var outer=context.outer; if(!GalaxyPowerOuterSource(outer)||Read(outer.expectedImage+0x5FDB275)!=0|| context.options.Length>128||Read(outer.service+0x330)!=(ulong)context.options.Length|| Pointer(outer.service+0x338)!=context.vector||context.options.Length!=0&&context.vector<0x10000)return false; for(var i=0;i(row)!=item.internalPowerId||Read(row+0x60)!=item.rawRed|| Read(row+0x64)!=item.rawGreen||Read(row+0x68)!=item.rawBlue)return false; } return true; } catch{return false;} } static bool CopyGalaxyPowerOuterStyle(GalaxyPowerOuterStyleContext context,ulong address,double[] position,out GalaxyPowerOuterStyleFact? result) { result=null; try { var outer=context.outer; if(!GalaxyPowerOuterStyleStable(context)||!CopyGalaxyPowerOuterVisible(outer,address,position,out var visible))return false; if(visible!=true)return true; if(!GalaxyPowerActivityFind(outer.service+0x3C0,address,-1,0x180,16,out var node))return false; if(node==0)return true; // Unobserved original metadata is not a grey classification. var metadata=node+0x10;var owner=Read(metadata);var state=Read(metadata+0xC); var flags=Read(metadata+0x4C); if(state is <0 or >65535)return false; float[] raw,linear; if(state!=0&&owner<(ulong)context.options.Length) { var option=context.options[(int)owner];raw=[option.rawRed,option.rawGreen,option.rawBlue]; linear=raw.Select(GalaxyPowerGeometryLinearColour).ToArray(); } else { // Exact selector: state0 tests contest flags+4C, not the // unoccupied Power mask+28. Invalid owner uses original grey. var value=state==0&&BitOperations.PopCount(flags)>1?1f:state==0&&flags!=0?1f:.4f; linear=[value,value,value];var display=GalaxyPowerOuterRawColour(value);raw=[display,display,display]; } if(raw.Any(c=>!float.IsFinite(c))||linear.Any(c=>!float.IsFinite(c))|| !GalaxyPowerOuterStyleStable(context)||Read(node)!=address||Read(metadata)!=owner|| Read(metadata+0xC)!=state||Read(metadata+0x4C)!=flags|| !CopyGalaxyPowerOuterVisible(outer,address,position,out visible)||visible!=true)return false; result=new(raw,linear,.7f,1);return true; } catch{return false;} } static bool TryReadGalaxyPowerOuterStyle(GalaxyPowerOuterContext context,ulong address,double[] position,out GalaxyPowerOuterStyleFact? result) { result=null; if(context.style is not {} style||!TryReadGalaxyPowerOuterVisible(context,address,position,out var visible))return false; return visible!=true||CopyGalaxyPowerOuterStyle(style,address,position,out result); } }