There was a problem with alignment of structures. There is a code (not mine, this code is compiled under x64) in C ++:
#ifndef ETS2_TELEMETRY_COMMON_HPP #define ETS2_TELEMETRY_COMMON_HPP // This file contains "Common definitions" for this ETS2 telemetry plug-in. // This includes: // - Debug logging detail options // - Shared memory map struct layout // - [..] #define ETS2_PLUGIN_REVID 5 #define ETS2_PLUGIN_LOGGING_ON 0 #define ETS2_PLUGIN_LOGGING_SHAREDMEMORY 0 #define ETS2_PLUGIN_FILENAME_PREFIX "C:\ets2telem_" #if ETS2_PLUGIN_LOGGING_ON == 1 #define SDK_ENABLE_LOGGING #endif #define ETS2_PLUGIN_MMF_NAME TEXT("Local\\SimTelemetryETS2") #define ETS2_PLUGIN_MMF_SIZE (16*1024) #define TRUCK_STRING_OFFSET 15*1024 #define TRAILER_STRING_OFFSET TRUCK_STRING_OFFSET+64 typedef struct ets2TelemetryMap_s { unsigned int time; unsigned int paused; struct { unsigned int ets2_telemetry_plugin_revision; unsigned int ets2_version_major; unsigned int ets2_version_minor; } tel_revId; // All variables per revision are packed into 1 struct. // Newer revisions must contain identical struct layouts/lengths, even if variabeles become deprecated. // Replaced/new variabeles should be added in seperate structs struct { bool engine_enabled; bool trailer_attached; // vehicle dynamics float speed; float accelerationX; float accelerationY; float accelerationZ; float coordinateX; float coordinateY; float coordinateZ; float rotationX; float rotationY; float rotationZ; // drivetrain essentials int gear; int gears; int gearRanges; int gearRangeActive; float engineRpm; float engineRpmMax; float fuel; float fuelCapacity; float fuelRate; // ! Not working float fuelAvgConsumption; // user input float userSteer; float userThrottle; float userBrake; float userClutch; float gameSteer; float gameThrottle; float gameBrake; float gameClutch; // truck & trailer float truckWeight; float trailerWeight; int modelType[2]; int trailerType[2]; // ! deprecated } tel_rev1; struct { long time_abs; int gears_reverse; // Trailer ID & display name float trailerMass; char trailerId[64]; char trailerName[64]; // Job information int jobIncome; int time_abs_delivery; char citySrc[64]; char cityDst[64]; char compSrc[64]; char compDst[64]; } tel_rev2; struct { int retarderBrake; int shifterSlot; int shifterToggle; int fill; bool cruiseControl; bool wipers; bool parkBrake; bool motorBrake; bool electricEnabled; bool engineEnabled; bool blinkerLeftActive; bool blinkerRightActive; bool blinkerLeftOn; bool blinkerRightOn; bool lightsParking; bool lightsBeamLow; bool lightsBeamHigh; bool lightsAuxFront; bool lightsAuxRoof; bool lightsBeacon; bool lightsBrake; bool lightsReverse; bool batteryVoltageWarning; bool airPressureWarning; bool airPressureEmergency; bool adblueWarning; bool oilPressureWarning; bool waterTemperatureWarning; float airPressure; float brakeTemperature; int fuelWarning; float adblue; float adblueConsumption; float oilPressure; float oilTemperature; float waterTemperature; float batteryVoltage; float lightsDashboard; float wearEngine; float wearTransmission; float wearCabin; float wearChassis; float wearWheels; float wearTrailer; float truckOdometer; float cruiseControlSpeed; // General info about the truck etc; char truckMake[64]; char truckMakeId[64]; char truckModel[64]; } tel_rev3; struct { float speedLimit; float routeDistance; float routeTime; float fuelRange; float gearRatiosForward[24]; float gearRatiosReverse[8]; float gearDifferential; int gearDashboard; } tel_rev4; // added in sdk1.5 struct { bool onJob; bool jobFinished; } tel_rev5; } ets2TelemetryMap_t; #endif And there is the following code in C # (also not mine) that gets this structure.
[StructLayout(LayoutKind.Explicit)] public unsafe struct Ets2SdkData { [FieldOffset(0)] public uint time; [FieldOffset(4)] public uint paused; [FieldOffset(8)] public uint ets2_telemetry_plugin_revision; [FieldOffset(12)] public uint ets2_version_major; [FieldOffset(16)] public uint ets2_version_minor; //***** REVISION 1 ****** // [FieldOffset(20), MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] public byte[] flags; //vehicle dynamics [FieldOffset(24)] public float speed; [FieldOffset(28)] public float accelerationX; [FieldOffset(32)] public float accelerationY; [FieldOffset(36)] public float accelerationZ; [FieldOffset(40)] public float coordinateX; [FieldOffset(44)] public float coordinateY; [FieldOffset(48)] public float coordinateZ; [FieldOffset(52)] public float rotationX; [FieldOffset(56)] public float rotationY; [FieldOffset(60)] public float rotationZ; //drivetrain essentials [FieldOffset(64)] public int gear; [FieldOffset(68)] public int gears; [FieldOffset(72)] public int gearRanges; [FieldOffset(76)] public int gearRangeActive; [FieldOffset(80)] public float engineRpm; [FieldOffset(84)] public float engineRpmMax; [FieldOffset(88)] public float fuel; [FieldOffset(92)] public float fuelCapacity; [FieldOffset(96)] public float fuelRate; [FieldOffset(100)] public float fuelAvgConsumption; // user input [FieldOffset(104)] public float userSteer; [FieldOffset(108)] public float userThrottle; [FieldOffset(112)] public float userBrake; [FieldOffset(116)] public float userClutch; [FieldOffset(120)] public float gameSteer; [FieldOffset(124)] public float gameThrottle; [FieldOffset(128)] public float gameBrake; [FieldOffset(132)] public float gameClutch; //truck & trailer [FieldOffset(136)] public float truckWeight; [FieldOffset(140)] public float trailerWeight; [FieldOffset(144)] public int modelOffset; [FieldOffset(148)] public int modelLength; [FieldOffset(152)] public int trailerOffset; [FieldOffset(156)] public int trailerLength; //***** REVISION 2 ****** // [FieldOffset(160)] public int timeAbsolute; [FieldOffset(164)] public int gearsReverse; [FieldOffset(168)] public float trailerMass; [FieldOffset(172), MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] public byte[] trailerId; [FieldOffset(236), MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] public byte[] trailerName; [FieldOffset(300)] public int jobIncome; [FieldOffset(304)] public int jobDeadline; [FieldOffset(308), MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] public byte[] jobCitySource; [FieldOffset(372), MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] public byte[] jobCityDestination; [FieldOffset(436), MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] public byte[] jobCompanySource; [FieldOffset(500), MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] public byte[] jobCompanyDestination; //***** REVISION 3 ****** // [FieldOffset(564)] public int retarderBrake; [FieldOffset(568)] public int shifterSlot; [FieldOffset(572)] public int shifterToggle; [FieldOffset(576)] public int fill; [FieldOffset(580), MarshalAs(UnmanagedType.ByValArray, SizeConst = 24)] public byte[] aux; [FieldOffset(604)] public float airPressure; [FieldOffset(608)] public float brakeTemperature; [FieldOffset(612)] public int fuelWarning; [FieldOffset(616)] public float adblue; [FieldOffset(620)] public float adblueConsumption; [FieldOffset(624)] public float oilPressure; [FieldOffset(628)] public float oilTemperature; [FieldOffset(632)] public float waterTemperature; [FieldOffset(636)] public float batteryVoltage; [FieldOffset(640)] public float lightsDashboard; [FieldOffset(644)] public float wearEngine; [FieldOffset(648)] public float wearTransmission; [FieldOffset(652)] public float wearCabin; [FieldOffset(656)] public float wearChassis; [FieldOffset(660)] public float wearWheels; [FieldOffset(664)] public float wearTrailer; [FieldOffset(668)] public float truckOdometer; [FieldOffset(672)] public float cruiseControlSpeed; [FieldOffset(676), MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] public byte[] truckMake; [FieldOffset(740), MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] public byte[] truckMakeId; [FieldOffset(804), MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] public byte[] truckModel; // ***** REVISION 4 ****** // [FieldOffset(868)] public float speedLimit; [FieldOffset(872)] public float routeDistance; [FieldOffset(876)] public float routeTime; [FieldOffset(880)] public float fuelRange; [FieldOffset(884), MarshalAs(UnmanagedType.ByValArray, SizeConst = 24)] public float[] gearRatioForward; [FieldOffset(980), MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public float[] gearRatioReverse; [FieldOffset(1012)] public float gearRatioDifferential; [FieldOffset(1016)] public int gearDashboard; [FieldOffset(1020)] public byte onJob; [FieldOffset(1021)] public byte jobFinished; public bool GetBool(Ets2SdkBoolean i) { if (i == Ets2SdkBoolean.TrailerAttached) return flags[1] > 0; return aux[(int)i] > 0; } } This code in C # works if the target platform is set to "x86" in the project properties, but if you change it to "x64" (which I need to do), then when executing the code, errors like this immediately begin:
Failed to load type "Ets2SdkData2" ... because it contains an object field with an offset of 20, which is incorrectly aligned or overlapped by a field that does not represent an object. "
From the description of the error, as I understood that " FieldOffset " is not correctly specified on all variables of the type " byte []".
Here the question arises: if for a project with a target platform - x86, the "FieldOffset" property is set correctly everywhere and the program receives all the data, then what should it be "FieldOffset" in the project with a target platform - x64?