Rise
The Vieneo Province
Loading...
Searching...
No Matches
Tests/Protocol11Tests.cpp

Source at documentation-generation time. See Test catalog for fixture associations.

1#include "../TelemetryProtocolContract.h"
2#include "../Protocol/TerrainWeather.h"
3#include "../Viewscreen/RainAir.h"
4#include <iostream>
5#include <cstddef>
6#include <cstring>
7
8// Fixed Win32 ABI baselines, including client-only helper structures. These
9// assertions detect accidental layout changes without another protocol header.
10// Coordinate intentional wire changes with Server.NET/RakNet before updating.
11#define LAYOUT(T, Size, Alignment) static_assert(sizeof(T)==Size && alignof(T)==Alignment, #T " layout");
12LAYOUT(VECTOR2SHORT, 4, 2)
13LAYOUT(SVesselDC, 84, 4)
14LAYOUT(SWeaponPacket, 40, 4)
15LAYOUT(SVerbiage, 1024, 4)
16LAYOUT(SDeviceMessage, 360, 2)
17LAYOUT(SSuperPacket, 180, 4)
18LAYOUT(SErrorPacket, 516, 4)
19LAYOUT(SInventory, 44, 4)
20LAYOUT(SPacketMenu, 532, 2)
21LAYOUT(SPacketBig, 92, 4)
22LAYOUT(SServerPacket, 20, 4)
23LAYOUT(SServerPacketNew, 68, 4)
24LAYOUT(SClientPacket, 20, 4)
25LAYOUT(SClientPacketNew, 72, 4)
26LAYOUT(SServerPacketChar, 16, 2)
27LAYOUT(SRenderVertex, 12, 4)
28LAYOUT(SRenderPoint, 16, 4)
29LAYOUT(SRenderRow, 776, 4)
30LAYOUT(SRenderGrid, 49156, 4)
31LAYOUT(SRenderWeather, 12, 2)
32LAYOUT(SPlotWeatherHeader, 16, 4)
33LAYOUT(SPlotWeatherRow, 784, 4)
34LAYOUT(SPlotWeatherGrid, 49168, 4)
35LAYOUT(SAssayVertex, 4, 1)
36LAYOUT(SAssayGrid, 104, 2)
37LAYOUT(Slayout, 16, 4)
38LAYOUT(SRenderBuilding, 24, 4)
39LAYOUT(SObject, 12, 4)
40LAYOUT(SPlotData, 256, 4)
41LAYOUT(SScanData, 132, 4)
42LAYOUT(SDockingPorts, 156, 4)
43LAYOUT(SLoginData, 33, 1)
44LAYOUT(SSubscribeData, 134, 2)
45LAYOUT(Swaypoint, 212, 4)
46LAYOUT(Snode, 56, 4)
47LAYOUT(SInventoryHelper, 4, 1)
48LAYOUT(SPacketHuge, 260, 4)
49LAYOUT(SPlayerData, 424, 8)
50#undef LAYOUT
51
52// Telemetry offsets match the corresponding C# definitions. A native vector's
53// offset is the offset of its first scalar component in the managed packet.
54#define OFFSET(T, Field, Byte) static_assert(offsetof(T,Field)==Byte, #T "." #Field " offset");
55OFFSET(SRenderWeather, precipitation, 0)
56OFFSET(SRenderWeather, turbulence, 1)
57OFFSET(SRenderWeather, ceiling, 2)
58OFFSET(SRenderWeather, snowDepthMm, 4)
59OFFSET(SRenderWeather, surfaceWaterTenthsMm, 5)
60OFFSET(SRenderWeather, snowAgeHours, 6)
61OFFSET(SRenderWeather, unused, 7)
62OFFSET(SRenderWeather, visibility, 8)
63OFFSET(SRenderWeather, windDirectionRadians, 10)
64OFFSET(SRenderWeather, windSpeedMs, 11)
65OFFSET(SVesselDC, rainAir, 57)
66OFFSET(SServerPacketNew, array, 0)
67OFFSET(SServerPacketNew, onlyOne, 1)
68OFFSET(SServerPacketNew, sampleTimeMs, 2)
69OFFSET(SServerPacketNew, position, 4)
70OFFSET(SServerPacketNew, velocity, 16)
71OFFSET(SServerPacketNew, orientation, 28)
72OFFSET(SServerPacketNew, pitch1, 44)
73OFFSET(SServerPacketNew, roll1, 46)
74OFFSET(SServerPacketNew, yaw1, 48)
75OFFSET(SServerPacketNew, ai, 50)
76OFFSET(SServerPacketNew, aj, 52)
77OFFSET(SServerPacketNew, ak, 54)
78OFFSET(SServerPacketNew, tx, 56)
79OFFSET(SServerPacketNew, ty, 57)
80OFFSET(SServerPacketNew, tz, 58)
81OFFSET(SServerPacketNew, tenthsMs, 59)
82OFFSET(SServerPacketNew, sequence, 60)
83OFFSET(SServerPacketNew, pitchdeflect, 62)
84OFFSET(SServerPacketNew, rolldeflect, 63)
85OFFSET(SServerPacketNew, yawdeflect, 64)
86OFFSET(SServerPacketNew, steerdeflect, 65)
87OFFSET(SServerPacketNew, sourceRevision, 66)
88OFFSET(SClientPacketNew, position, 0)
89OFFSET(SClientPacketNew, velocity, 12)
90OFFSET(SClientPacketNew, orientation, 24)
91OFFSET(SClientPacketNew, pitch1, 40)
92OFFSET(SClientPacketNew, roll1, 42)
93OFFSET(SClientPacketNew, yaw1, 44)
94OFFSET(SClientPacketNew, ai, 46)
95OFFSET(SClientPacketNew, aj, 48)
96OFFSET(SClientPacketNew, ak, 50)
97OFFSET(SClientPacketNew, tx, 52)
98OFFSET(SClientPacketNew, ty, 53)
99OFFSET(SClientPacketNew, tz, 54)
100OFFSET(SClientPacketNew, pitchdeflect, 55)
101OFFSET(SClientPacketNew, rolldeflect, 56)
102OFFSET(SClientPacketNew, yawdeflect, 57)
103OFFSET(SClientPacketNew, airframeTemp, 58)
104OFFSET(SClientPacketNew, fuel, 60)
105OFFSET(SClientPacketNew, reference, 62)
106OFFSET(SClientPacketNew, airIceAccumulationMm, 63)
107OFFSET(SClientPacketNew, pitchTrim, 64)
108OFFSET(SClientPacketNew, steerdeflect, 66)
109OFFSET(SClientPacketNew, groundIceAccumulationMm, 67)
110OFFSET(SClientPacketNew, cabinPressureMb, 68)
111OFFSET(SClientPacketNew, sampleTimeMs, 70)
112OFFSET(SVesselDC, padding2, 58)
113#undef OFFSET
114
115int main()
116{
117 for(const size_t existing : {sizeof(SServerPacket),sizeof(SPacketBig),sizeof(SPacketHuge),
118 sizeof(SWeaponPacket),sizeof(SRenderPoint),sizeof(SRenderRow),sizeof(SAssayGrid),
119 sizeof(SRenderGrid),sizeof(SRenderBuilding),sizeof(SPacketMenu)})
120 if(existing==sizeof(SPlotWeatherGrid) || existing==sizeof(SPlotWeatherRow))
121 {std::cerr<<"FAIL: plot weather collides with a size-dispatched message\n";return 1;}
122
123 for(const int health:{-1,0,1,127})
124 {
125 unsigned char bytes[84]{};
126 bytes[57]=static_cast<unsigned char>(health);
127 bytes[58]=0xa5; // Reserved padding must not gate or override equipment health.
128 SVesselDC damage{};
129 memcpy(&damage,bytes,sizeof(damage));
130 const auto expected=health<0?RainAir::State::Off:health==0?RainAir::State::Unavailable:RainAir::State::Active;
131 if(damage.rainAir!=health ||
132 RainAir::Evaluate(damage.rainAir,true,true,1,true)!=expected)
133 {std::cerr<<"FAIL: server rain-air byte or availability differs\n";return 1;}
134 }
135 std::cout<<"PASS: rainAir wire byte -1/0/1/127 controls availability; padding is ignored\n";
136 SClientPacketNew packet;
137 memset(&packet,0,sizeof(packet));
138 packet.position={2933.25f,-200.5f,11.625f};
139 packet.velocity={-.123f,7.875f,.001f};
140 packet.orientation={.1f,-.2f,.3f,.9f};
141 packet.pitch1=-31700;packet.yaw1=128;
142 packet.tz=-127;packet.airframeTemp=500;
143 packet.sampleTimeMs=65535;
144 // Captured by compiling and marshaling Server.NET/RakNet/SClientPacketNew.cs
145 // with the values above (2026-10-03), independently of the native definition.
146 constexpr unsigned char expectedBytes[]={
147 0x00, 0x54, 0x37, 0x45, 0x00, 0x80, 0x48, 0xc3, 0x00, 0x00, 0x3a, 0x41,
148 0x6d, 0xe7, 0xfb, 0xbd, 0x00, 0x00, 0xfc, 0x40, 0x6f, 0x12, 0x83, 0x3a,
149 0xcd, 0xcc, 0xcc, 0x3d, 0xcd, 0xcc, 0x4c, 0xbe, 0x9a, 0x99, 0x99, 0x3e,
150 0x66, 0x66, 0x66, 0x3f, 0x2c, 0x84, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00,
151 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x00, 0x00, 0x00, 0xf4, 0x01,
152 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff,
153 };
154 static_assert(sizeof(expectedBytes)==sizeof(packet), "client telemetry fixture size");
155 if(memcmp(&packet,expectedBytes,sizeof(packet))){std::cerr<<"FAIL: client telemetry bytes differ from C# fixture\n";return 1;}
156 std::cout<<"PASS: native protocol sizes and alignments, terrain weather layouts, telemetry offsets, and C# telemetry bytes\n";
157}
float fuel
Definition globals.cpp:90
State Evaluate(int equipment, bool selected, bool operating, float power, bool engineAvailable)
Definition RainAir.h:10
unsigned short sampleTimeMs
RiseMath::Vector3 velocity
RiseMath::Quaternion orientation
RiseMath::Vector3 position
signed char rainAir