Below is a small example of the code, is there something I am missing or have gotten wrong? I have gotten it working when the code is run before the game is launched in the startup menu, but once in game the `SimConnect_SetDataOnSimObject` seem to be ignored or immediately overwritten.
My goal with this is to have an external program change these values and then the simulation can keep running without having to restart or open a new scenario. Stepping through the code shows that all `AddToDataDefinition`s and `SetDataOnSimObject`s succeed but I'm not sure why the changes wouldn't then be reflected in game.
If anyone could point me in the right direction I would be greatly appreciate it!
Code: Select all
#include <Windows.h>
#include <tchar.h>
#include <stdio.h>
#include "SimConnect.h"
#include <strsafe.h>
#include <fstream>
static enum DATA_DEFINE_ID {
ALTITUDE,
LATITUDE,
LONGITUDE,
AIRSPEED
};
HANDLE hSimConnect = NULL;
int main() {
HRESULT hr;
hr = SimConnect_Open(&hSimConnect, "SimConnect Unity Plugin", NULL, 0, 0, 0);
hr = SimConnect_AddToDataDefinition(hSimConnect, ALTITUDE, "PLANE ALTITUDE", "feet", SIMCONNECT_DATATYPE_FLOAT32, 0, SIMCONNECT_UNUSED);
hr = SimConnect_AddToDataDefinition(hSimConnect, LATITUDE, "PLANE LATITUDE", "degrees", SIMCONNECT_DATATYPE_FLOAT32, 0, SIMCONNECT_UNUSED);
hr = SimConnect_AddToDataDefinition(hSimConnect, LONGITUDE, "PLANE LONGITUDE", "degrees", SIMCONNECT_DATATYPE_FLOAT32, 0, SIMCONNECT_UNUSED);
hr = SimConnect_AddToDataDefinition(hSimConnect, AIRSPEED, "AIRSPEED TRUE", "knots", SIMCONNECT_DATATYPE_INT32, 0, SIMCONNECT_UNUSED);
double altitude = 25000;
double latitude = 30.352651;
double longitude = -87.320735;
int airspeed = 400;
hr = SimConnect_SetDataOnSimObject(hSimConnect, ALTITUDE, SIMCONNECT_OBJECT_ID_USER, 0, 0, sizeof(altitude), &altitude);
hr = SimConnect_SetDataOnSimObject(hSimConnect, LATITUDE, SIMCONNECT_OBJECT_ID_USER, 0, 0, sizeof(latitude), &latitude);
hr = SimConnect_SetDataOnSimObject(hSimConnect, LONGITUDE, SIMCONNECT_OBJECT_ID_USER, 0, 0, sizeof(longitude), &longitude);
hr = SimConnect_SetDataOnSimObject(hSimConnect, AIRSPEED, SIMCONNECT_OBJECT_ID_USER, 0, 0, sizeof(airspeed), &airspeed);
}