rado_dimitrov66

Untitled

May 13th, 2026
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | Gaming | 0 0
  1. #include <windows.h>
  2. #include <tchar.h>
  3. #include <stdio.h>
  4. #include <strsafe.h>
  5.  
  6. #include "SimConnect.h"
  7.  
  8. HANDLE hSimConnect = NULL;
  9. bool quit = false;
  10. bool flightLoaded = false;
  11.  
  12. static enum EVENT_ID {
  13. EVENT_FLIGHT_LOAD,
  14. EVENT_RECUR_1SEC,
  15. EVENT_RECUR_FRAME,
  16. EVENT_SIM_START,
  17. EVENT_SIM
  18. };
  19.  
  20. static enum DEFINE_ID {
  21. POSITION_PLANE
  22. };
  23.  
  24. static enum REQUEST_ID {
  25. REQUEST_PLANE_POSITION
  26. };
  27.  
  28. struct PlanePosition {
  29. double latitude;
  30. double longitude;
  31. double altitude;
  32. double heading;
  33. bool onGround;
  34. };
  35.  
  36.  
  37. void CALLBACK MyDispatchProc(SIMCONNECT_RECV* pData, DWORD cbData, void* pContext)
  38. {
  39.  
  40. switch (pData->dwID) {
  41. case SIMCONNECT_RECV_ID_QUIT: {
  42.  
  43. quit = true;
  44. break;
  45. }
  46.  
  47. case SIMCONNECT_RECV_ID_EVENT: {
  48. SIMCONNECT_RECV_EVENT* evt = (SIMCONNECT_RECV_EVENT*)pData;
  49. if (evt->uEventID == EVENT_SIM_START) {
  50. printf("\nSim started");
  51. flightLoaded = true;
  52. }
  53.  
  54. if (evt->uEventID == EVENT_SIM) {
  55. printf("\nSim started");
  56. flightLoaded = true;
  57. }
  58. break;
  59. }
  60.  
  61. case SIMCONNECT_RECV_ID_EVENT_FILENAME: {
  62. SIMCONNECT_RECV_EVENT_FILENAME* evt = (SIMCONNECT_RECV_EVENT_FILENAME*)pData;
  63.  
  64. if (evt->uEventID == EVENT_FLIGHT_LOAD) {
  65. printf("\nFlight loaded");
  66. flightLoaded = true;
  67. }
  68.  
  69. break;
  70. }
  71. case SIMCONNECT_RECV_ID_SIMOBJECT_DATA: {
  72.  
  73.  
  74.  
  75. SIMCONNECT_RECV_SIMOBJECT_DATA* pObjData = (SIMCONNECT_RECV_SIMOBJECT_DATA*)pData;
  76.  
  77. switch (pObjData->dwRequestID) {
  78. case REQUEST_PLANE_POSITION:
  79.  
  80. PlanePosition* planePos = (PlanePosition*)&pObjData->dwData;
  81. printf("\nPlane Position: Latitude: %f, Longitude: %f, Altitude: %f, Heading: %f, On Ground: %d ",
  82. planePos->latitude, planePos->longitude, planePos->altitude, planePos->heading, planePos->onGround);
  83. break;
  84. };
  85.  
  86. break;
  87. }
  88. }
  89. };
  90.  
  91. void addDataDefinition()
  92. {
  93. SimConnect_AddToDataDefinition(hSimConnect, POSITION_PLANE, "Plane Latitude", "degrees");
  94. SimConnect_AddToDataDefinition(hSimConnect, POSITION_PLANE, "Plane Longitude", "degrees");
  95. SimConnect_AddToDataDefinition(hSimConnect, POSITION_PLANE, "Plane Altitude", "feet");
  96. SimConnect_AddToDataDefinition(hSimConnect, POSITION_PLANE, "PLANE HEADING DEGREES TRUE", "degrees");
  97. SimConnect_AddToDataDefinition(hSimConnect, POSITION_PLANE, "SIM ON GROUND", "bool");
  98.  
  99. SimConnect_RequestDataOnSimObject(hSimConnect, REQUEST_PLANE_POSITION, POSITION_PLANE, SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD_SECOND);
  100. SimConnect_CallDispatch(hSimConnect, MyDispatchProc, NULL);
  101. }
  102.  
  103. void testOpenClose()
  104. {
  105. HRESULT hr;
  106.  
  107. hr = SimConnect_Open(&hSimConnect, "GSX Backend", NULL, 0, 0, 0);
  108.  
  109.  
  110. if (SUCCEEDED(hr))
  111. {
  112. printf("\nConnected to Flight Simulator!");
  113.  
  114. while (!quit)
  115. {
  116. HRESULT hrConnect = SimConnect_CallDispatch(hSimConnect, MyDispatchProc, NULL);
  117. Sleep(1);
  118.  
  119. if (FAILED(hrConnect)) {
  120. quit = true;
  121. break;
  122. }
  123.  
  124. SimConnect_SubscribeToSystemEvent(hSimConnect, EVENT_FLIGHT_LOAD, "FlightLoaded");
  125. ////SimConnect_SubscribeToSystemEvent(hSimConnect, EVENT_SIM_START, "SimStart");
  126. //SimConnect_SubscribeToSystemEvent(hSimConnect, EVENT_SIM, "Sim");
  127.  
  128. if (flightLoaded) {
  129. addDataDefinition();
  130. }
  131.  
  132. }
  133.  
  134. SimConnect_Close(hSimConnect);
  135. printf("\nDisconnected from Flight Simulator!");
  136.  
  137. }
  138. else {
  139. printf("\nFailed to connect to Flight Simulator!");
  140. }
  141. }
  142.  
  143. int __cdecl _tmain(int argc, _TCHAR* argv[])
  144. {
  145. testOpenClose();
  146. return 0;
  147. }
  148.  
Advertisement
Add Comment
Please, Sign In to add comment