├── .github └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── License.md ├── Readme.md ├── SimConnect.dll ├── build.rs ├── examples ├── aircraft_inputs │ └── main.rs ├── aircraft_updates │ └── main.rs └── aircraft_updates_on_change │ └── main.rs ├── libsrc ├── include │ └── SimConnect.hpp └── lib │ └── SimConnect.lib └── src └── lib.rs /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .vscode 3 | bindings.rs -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "bindgen" 7 | version = "0.69.4" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0" 10 | dependencies = [ 11 | "bitflags", 12 | "cexpr", 13 | "clang-sys", 14 | "itertools", 15 | "lazy_static", 16 | "lazycell", 17 | "log", 18 | "prettyplease", 19 | "proc-macro2", 20 | "quote", 21 | "regex", 22 | "rustc-hash", 23 | "shlex", 24 | "syn", 25 | "which", 26 | ] 27 | 28 | [[package]] 29 | name = "bitflags" 30 | version = "2.5.0" 31 | source = "registry+https://github.com/rust-lang/crates.io-index" 32 | checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" 33 | 34 | [[package]] 35 | name = "cexpr" 36 | version = "0.6.0" 37 | source = "registry+https://github.com/rust-lang/crates.io-index" 38 | checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" 39 | dependencies = [ 40 | "nom", 41 | ] 42 | 43 | [[package]] 44 | name = "cfg-if" 45 | version = "0.1.10" 46 | source = "registry+https://github.com/rust-lang/crates.io-index" 47 | checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" 48 | 49 | [[package]] 50 | name = "clang-sys" 51 | version = "1.0.0" 52 | source = "registry+https://github.com/rust-lang/crates.io-index" 53 | checksum = "9da1484c6a890e374ca5086062d4847e0a2c1e5eba9afa5d48c09e8eb39b2519" 54 | dependencies = [ 55 | "glob", 56 | "libc", 57 | "libloading", 58 | ] 59 | 60 | [[package]] 61 | name = "either" 62 | version = "1.8.1" 63 | source = "registry+https://github.com/rust-lang/crates.io-index" 64 | checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" 65 | 66 | [[package]] 67 | name = "glob" 68 | version = "0.3.0" 69 | source = "registry+https://github.com/rust-lang/crates.io-index" 70 | checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" 71 | 72 | [[package]] 73 | name = "itertools" 74 | version = "0.12.1" 75 | source = "registry+https://github.com/rust-lang/crates.io-index" 76 | checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" 77 | dependencies = [ 78 | "either", 79 | ] 80 | 81 | [[package]] 82 | name = "lazy_static" 83 | version = "1.4.0" 84 | source = "registry+https://github.com/rust-lang/crates.io-index" 85 | checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" 86 | 87 | [[package]] 88 | name = "lazycell" 89 | version = "1.3.0" 90 | source = "registry+https://github.com/rust-lang/crates.io-index" 91 | checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" 92 | 93 | [[package]] 94 | name = "libc" 95 | version = "0.2.144" 96 | source = "registry+https://github.com/rust-lang/crates.io-index" 97 | checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1" 98 | 99 | [[package]] 100 | name = "libloading" 101 | version = "0.6.3" 102 | source = "registry+https://github.com/rust-lang/crates.io-index" 103 | checksum = "2443d8f0478b16759158b2f66d525991a05491138bc05814ef52a250148ef4f9" 104 | dependencies = [ 105 | "cfg-if", 106 | "winapi", 107 | ] 108 | 109 | [[package]] 110 | name = "log" 111 | version = "0.4.11" 112 | source = "registry+https://github.com/rust-lang/crates.io-index" 113 | checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" 114 | dependencies = [ 115 | "cfg-if", 116 | ] 117 | 118 | [[package]] 119 | name = "memchr" 120 | version = "2.3.3" 121 | source = "registry+https://github.com/rust-lang/crates.io-index" 122 | checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" 123 | 124 | [[package]] 125 | name = "minimal-lexical" 126 | version = "0.2.1" 127 | source = "registry+https://github.com/rust-lang/crates.io-index" 128 | checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" 129 | 130 | [[package]] 131 | name = "nom" 132 | version = "7.1.3" 133 | source = "registry+https://github.com/rust-lang/crates.io-index" 134 | checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" 135 | dependencies = [ 136 | "memchr", 137 | "minimal-lexical", 138 | ] 139 | 140 | [[package]] 141 | name = "once_cell" 142 | version = "1.17.1" 143 | source = "registry+https://github.com/rust-lang/crates.io-index" 144 | checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" 145 | 146 | [[package]] 147 | name = "prettyplease" 148 | version = "0.2.20" 149 | source = "registry+https://github.com/rust-lang/crates.io-index" 150 | checksum = "5f12335488a2f3b0a83b14edad48dca9879ce89b2edd10e80237e4e852dd645e" 151 | dependencies = [ 152 | "proc-macro2", 153 | "syn", 154 | ] 155 | 156 | [[package]] 157 | name = "proc-macro2" 158 | version = "1.0.86" 159 | source = "registry+https://github.com/rust-lang/crates.io-index" 160 | checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" 161 | dependencies = [ 162 | "unicode-ident", 163 | ] 164 | 165 | [[package]] 166 | name = "quote" 167 | version = "1.0.36" 168 | source = "registry+https://github.com/rust-lang/crates.io-index" 169 | checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" 170 | dependencies = [ 171 | "proc-macro2", 172 | ] 173 | 174 | [[package]] 175 | name = "regex" 176 | version = "1.8.1" 177 | source = "registry+https://github.com/rust-lang/crates.io-index" 178 | checksum = "af83e617f331cc6ae2da5443c602dfa5af81e517212d9d611a5b3ba1777b5370" 179 | dependencies = [ 180 | "regex-syntax", 181 | ] 182 | 183 | [[package]] 184 | name = "regex-syntax" 185 | version = "0.7.1" 186 | source = "registry+https://github.com/rust-lang/crates.io-index" 187 | checksum = "a5996294f19bd3aae0453a862ad728f60e6600695733dd5df01da90c54363a3c" 188 | 189 | [[package]] 190 | name = "rustc-hash" 191 | version = "1.1.0" 192 | source = "registry+https://github.com/rust-lang/crates.io-index" 193 | checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" 194 | 195 | [[package]] 196 | name = "shlex" 197 | version = "1.1.0" 198 | source = "registry+https://github.com/rust-lang/crates.io-index" 199 | checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" 200 | 201 | [[package]] 202 | name = "simconnect" 203 | version = "0.3.2" 204 | dependencies = [ 205 | "bindgen", 206 | ] 207 | 208 | [[package]] 209 | name = "syn" 210 | version = "2.0.67" 211 | source = "registry+https://github.com/rust-lang/crates.io-index" 212 | checksum = "ff8655ed1d86f3af4ee3fd3263786bc14245ad17c4c7e85ba7187fb3ae028c90" 213 | dependencies = [ 214 | "proc-macro2", 215 | "quote", 216 | "unicode-ident", 217 | ] 218 | 219 | [[package]] 220 | name = "unicode-ident" 221 | version = "1.0.8" 222 | source = "registry+https://github.com/rust-lang/crates.io-index" 223 | checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" 224 | 225 | [[package]] 226 | name = "which" 227 | version = "4.4.0" 228 | source = "registry+https://github.com/rust-lang/crates.io-index" 229 | checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269" 230 | dependencies = [ 231 | "either", 232 | "libc", 233 | "once_cell", 234 | ] 235 | 236 | [[package]] 237 | name = "winapi" 238 | version = "0.3.9" 239 | source = "registry+https://github.com/rust-lang/crates.io-index" 240 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 241 | dependencies = [ 242 | "winapi-i686-pc-windows-gnu", 243 | "winapi-x86_64-pc-windows-gnu", 244 | ] 245 | 246 | [[package]] 247 | name = "winapi-i686-pc-windows-gnu" 248 | version = "0.4.0" 249 | source = "registry+https://github.com/rust-lang/crates.io-index" 250 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 251 | 252 | [[package]] 253 | name = "winapi-x86_64-pc-windows-gnu" 254 | version = "0.4.0" 255 | source = "registry+https://github.com/rust-lang/crates.io-index" 256 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 257 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "simconnect" 3 | license = "MIT" 4 | description = "Rust bindings for SimConnect" 5 | version = "0.3.2" 6 | authors = ["Connor T"] 7 | edition = "2018" 8 | 9 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 10 | [[example]] 11 | name = "aircraft_updates_on_change" 12 | path = "examples/aircraft_updates_on_change/main.rs" 13 | 14 | [[example]] 15 | name = "aircraft_updates" 16 | path = "examples/aircraft_updates/main.rs" 17 | 18 | [[example]] 19 | name = "aircraft_inputs" 20 | path = "examples/aircraft_inputs/main.rs" 21 | 22 | [build-dependencies] 23 | bindgen = "0.69.4" 24 | -------------------------------------------------------------------------------- /License.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Connor Tam 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | ![crates.io](https://img.shields.io/crates/v/simconnect) 2 | 3 | # SimConnect Bindings for Rust 4 | 5 | ## Requirements 6 | 7 | - [CLang](https://clang.llvm.org/get_started.html) (See the [Rust Bindgen Documentation](https://rust-lang.github.io/rust-bindgen/requirements.html)) 8 | - MSVC x64 Rust build (`x86_64-pc-windows-msvc`, see [The rustup book](https://rust-lang.github.io/rustup/installation/windows.html)) 9 | 10 | ## Using 11 | 12 | Add this to your `Cargo.toml` 13 | 14 | ```toml 15 | [dependencies] 16 | simconnect = "0.3.2" 17 | ``` 18 | 19 | ## Building 20 | 21 | _The SimConnect binaries are included within this repository, but they may not be up-to-date._ 22 | 23 | 1. run `cargo build` 24 | 2. Add `use simconnect` at the top of your file 25 | 26 | ## Example 27 | 28 | Read float position data 29 | 30 | ``` 31 | cargo run --example aircraft_updates 32 | ``` 33 | 34 | Requests tagged data with thresholds from SimConnect and reads floats/strings 35 | 36 | ``` 37 | cargo run --example aircraft_updates_on_change 38 | ``` 39 | 40 | _You must have SimConnect.dll in the same directory as the compiled exe for it to run (e.g. in )_ 41 | 42 | ### Remarks 43 | 44 | I have not tested every single function from the api. If you find an error, feel free to make an issue or a pull request. 45 | -------------------------------------------------------------------------------- /SimConnect.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sequal32/simconnect-rust/0fa414cd3859187c605edb388d5047675b1f8778/SimConnect.dll -------------------------------------------------------------------------------- /build.rs: -------------------------------------------------------------------------------- 1 | use std::{env, path::PathBuf}; 2 | 3 | fn main() { 4 | println!("cargo:rustc-link-search=libsrc/lib"); 5 | println!("cargo:rustc-link-lib=static=SimConnect"); 6 | 7 | let bindings = bindgen::Builder::default() 8 | .header("libsrc/include/SimConnect.hpp") 9 | .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) 10 | .allowlist_var("SIMCONNECT_UNUSED") 11 | .allowlist_var("SIMCONNECT_OBJECT_ID_USER") 12 | .allowlist_var("SIMCONNECT_CAMERA_IGNORE_FIELD") 13 | .allowlist_var("SIMCONNECT_CLIENTDATA_MAX_SIZE") 14 | .allowlist_var("SIMCONNECT_GROUP_PRIORITY_HIGHEST") 15 | .allowlist_var("SIMCONNECT_GROUP_PRIORITY_HIGHEST_MASKABLE") 16 | .allowlist_var("SIMCONNECT_GROUP_PRIORITY_STANDARD") 17 | .allowlist_var("SIMCONNECT_GROUP_PRIORITY_DEFAULT") 18 | .allowlist_var("SIMCONNECT_GROUP_PRIORITY_LOWEST") 19 | .allowlist_var("MAX_METAR_LENGTH") 20 | .allowlist_var("MAX_THERMAL_SIZE") 21 | .allowlist_var("MAX_THERMAL_RATE") 22 | .allowlist_var("INITPOSITION_AIRSPEED_CRUISE") 23 | .allowlist_var("INITPOSITION_AIRSPEED_KEEP") 24 | .allowlist_var("SIMCONNECT_CLIENTDATATYPE_INT8") 25 | .allowlist_var("SIMCONNECT_CLIENTDATATYPE_INT16") 26 | .allowlist_var("SIMCONNECT_CLIENTDATATYPE_INT32") 27 | .allowlist_var("SIMCONNECT_CLIENTDATATYPE_INT64") 28 | .allowlist_var("SIMCONNECT_CLIENTDATATYPE_FLOAT32") 29 | .allowlist_var("SIMCONNECT_CLIENTDATATYPE_FLOAT64") 30 | .allowlist_var("SIMCONNECT_CLIENTDATAOFFSET_AUTO") 31 | .allowlist_var("SIMCONNECT_OPEN_CONFIGINDEX_LOCAL") 32 | .allowlist_var("SIMCONNECT_RECV_ID_VOR_LIST_HAS_NAV_SIGNAL") 33 | .allowlist_var("SIMCONNECT_RECV_ID_VOR_LIST_HAS_LOCALIZER") 34 | .allowlist_var("SIMCONNECT_RECV_ID_VOR_LIST_HAS_GLIDE_SLOPE") 35 | .allowlist_var("SIMCONNECT_RECV_ID_VOR_LIST_HAS_DME") 36 | .allowlist_var("SIMCONNECT_WAYPOINT_NONE") 37 | .allowlist_var("SIMCONNECT_WAYPOINT_SPEED_REQUESTED") 38 | .allowlist_var("SIMCONNECT_WAYPOINT_THROTTLE_REQUESTED") 39 | .allowlist_var("SIMCONNECT_WAYPOINT_COMPUTE_VERTICAL_SPEED") 40 | .allowlist_var("SIMCONNECT_WAYPOINT_ALTITUDE_IS_AGL") 41 | .allowlist_var("SIMCONNECT_WAYPOINT_ON_GROUND") 42 | .allowlist_var("SIMCONNECT_WAYPOINT_REVERSE") 43 | .allowlist_var("SIMCONNECT_WAYPOINT_WRAP_TO_FIRST") 44 | .allowlist_var("SIMCONNECT_EVENT_FLAG_DEFAULT") 45 | .allowlist_var("SIMCONNECT_EVENT_FLAG_FAST_REPEAT_TIMER") 46 | .allowlist_var("SIMCONNECT_EVENT_FLAG_SLOW_REPEAT_TIMER") 47 | .allowlist_var("SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY") 48 | .allowlist_var("SIMCONNECT_DATA_REQUEST_FLAG_DEFAULT") 49 | .allowlist_var("SIMCONNECT_DATA_REQUEST_FLAG_CHANGED") 50 | .allowlist_var("SIMCONNECT_DATA_REQUEST_FLAG_TAGGED") 51 | .allowlist_var("SIMCONNECT_DATA_SET_FLAG_DEFAULT") 52 | .allowlist_var("SIMCONNECT_DATA_SET_FLAG_TAGGED") 53 | .allowlist_var("SIMCONNECT_CREATE_CLIENT_DATA_FLAG_DEFAULT") 54 | .allowlist_var("SIMCONNECT_CREATE_CLIENT_DATA_FLAG_READ_ONLY") 55 | .allowlist_var("SIMCONNECT_CLIENT_DATA_REQUEST_FLAG_DEFAULT") 56 | .allowlist_var("SIMCONNECT_CLIENT_DATA_REQUEST_FLAG_CHANGED") 57 | .allowlist_var("SIMCONNECT_CLIENT_DATA_REQUEST_FLAG_TAGGED") 58 | .allowlist_var("SIMCONNECT_CLIENT_DATA_SET_FLAG_DEFAULT") 59 | .allowlist_var("SIMCONNECT_CLIENT_DATA_SET_FLAG_TAGGED") 60 | .allowlist_var("SIMCONNECT_VIEW_SYSTEM_EVENT_DATA_COCKPIT_2D") 61 | .allowlist_var("SIMCONNECT_VIEW_SYSTEM_EVENT_DATA_COCKPIT_VIRTUAL") 62 | .allowlist_var("SIMCONNECT_VIEW_SYSTEM_EVENT_DATA_ORTHOGONAL") 63 | .allowlist_var("SIMCONNECT_SOUND_SYSTEM_EVENT_DATA_MASTER") 64 | .allowlist_var("UNKNOWN_SENDID") 65 | .allowlist_var("UNKNOWN_INDEX") 66 | .allowlist_var("UNKNOWN_GROUP") 67 | .allowlist_var("SIMCONNECT_CLOUD_STATE_ARRAY_WIDTH") 68 | .allowlist_var("SIMCONNECT_CLOUD_STATE_ARRAY_SIZE") 69 | .allowlist_type("HANDLE") 70 | .allowlist_type("SIMCONNECT_RECV_ID") 71 | .allowlist_type("SIMCONNECT_DATATYPE") 72 | .allowlist_type("SIMCONNECT_EXCEPTION") 73 | .allowlist_type("SIMCONNECT_SIMOBJECT_TYPE") 74 | .allowlist_type("SIMCONNECT_STATE") 75 | .allowlist_type("SIMCONNECT_PERIOD") 76 | .allowlist_type("SIMCONNECT_MISSION_END") 77 | .allowlist_type("SIMCONNECT_CLIENT_DATA_PERIOD") 78 | .allowlist_type("SIMCONNECT_TEXT_TYPE") 79 | .allowlist_type("SIMCONNECT_TEXT_RESULT") 80 | .allowlist_type("SIMCONNECT_WEATHER_MODE") 81 | .allowlist_type("SIMCONNECT_FACILITY_LIST_TYPE") 82 | .allowlist_type("SIMCONNECT_RECV") 83 | .allowlist_type("SIMCONNECT_RECV_EXCEPTION") 84 | .allowlist_type("SIMCONNECT_RECV_OPEN") 85 | .allowlist_type("SIMCONNECT_RECV_QUIT") 86 | .allowlist_type("SIMCONNECT_RECV_EVENT") 87 | .allowlist_type("SIMCONNECT_RECV_EVENT_FILENAME") 88 | .allowlist_type("SIMCONNECT_RECV_EVENT_OBJECT_ADDREMOVE") 89 | .allowlist_type("SIMCONNECT_RECV_EVENT_FRAME") 90 | .allowlist_type("SIMCONNECT_RECV_EVENT_MULTIPLAYER_SERVER_STARTED") 91 | .allowlist_type("SIMCONNECT_RECV_EVENT_MULTIPLAYER_CLIENT_STARTED") 92 | .allowlist_type("SIMCONNECT_RECV_EVENT_MULTIPLAYER_SESSION_ENDED") 93 | .allowlist_type("SIMCONNECT_RECV_EVENT_RACE_END") 94 | .allowlist_type("SIMCONNECT_RECV_EVENT_RACE_LAP") 95 | .allowlist_type("SIMCONNECT_RECV_SIMOBJECT_DATA") 96 | .allowlist_type("SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE") 97 | .allowlist_type("SIMCONNECT_RECV_CLIENT_DATA") 98 | .allowlist_type("SIMCONNECT_RECV_WEATHER_OBSERVATION") 99 | .allowlist_type("SIMCONNECT_RECV_CLOUD_STATE") 100 | .allowlist_type("SIMCONNECT_RECV_ASSIGNED_OBJECT_ID") 101 | .allowlist_type("SIMCONNECT_RECV_RESERVED_KEY") 102 | .allowlist_type("SIMCONNECT_RECV_SYSTEM_STATE") 103 | .allowlist_type("SIMCONNECT_RECV_CUSTOM_ACTION") 104 | .allowlist_type("SIMCONNECT_RECV_EVENT_WEATHER_MODE") 105 | .allowlist_type("SIMCONNECT_RECV_FACILITIES_LIST") 106 | .allowlist_type("SIMCONNECT_DATA_FACILITY_AIRPORT") 107 | .allowlist_type("SIMCONNECT_RECV_AIRPORT_LIST") 108 | .allowlist_type("SIMCONNECT_DATA_FACILITY_WAYPOINT") 109 | .allowlist_type("SIMCONNECT_RECV_WAYPOINT_LIST") 110 | .allowlist_type("SIMCONNECT_DATA_FACILITY_NDB") 111 | .allowlist_type("SIMCONNECT_RECV_NDB_LIST") 112 | .allowlist_type("SIMCONNECT_DATA_FACILITY_VOR") 113 | .allowlist_type("SIMCONNECT_RECV_VOR_LIST") 114 | .allowlist_type("SIMCONNECT_RECV_PICK") 115 | .allowlist_function("SimConnect_MapClientEventToSimEvent") 116 | .allowlist_function("SimConnect_TransmitClientEvent") 117 | .allowlist_function("SimConnect_SetSystemEventState") 118 | .allowlist_function("SimConnect_AddClientEventToNotificationGroup") 119 | .allowlist_function("SimConnect_RemoveClientEvent") 120 | .allowlist_function("SimConnect_SetNotificationGroupPriority") 121 | .allowlist_function("SimConnect_ClearNotificationGroup") 122 | .allowlist_function("SimConnect_RequestNotificationGroup") 123 | .allowlist_function("SimConnect_AddToDataDefinition") 124 | .allowlist_function("SimConnect_ClearDataDefinition") 125 | .allowlist_function("SimConnect_RequestDataOnSimObject") 126 | .allowlist_function("SimConnect_RequestDataOnSimObjectType") 127 | .allowlist_function("SimConnect_SetDataOnSimObject") 128 | .allowlist_function("SimConnect_MapInputEventToClientEvent") 129 | .allowlist_function("SimConnect_SetInputGroupPriority") 130 | .allowlist_function("SimConnect_RemoveInputEvent") 131 | .allowlist_function("SimConnect_ClearInputGroup") 132 | .allowlist_function("SimConnect_SetInputGroupState") 133 | .allowlist_function("SimConnect_RequestReservedKey") 134 | .allowlist_function("SimConnect_SubscribeToSystemEvent") 135 | .allowlist_function("SimConnect_UnsubscribeFromSystemEvent") 136 | .allowlist_function("SimConnect_WeatherRequestInterpolatedObservation") 137 | .allowlist_function("SimConnect_WeatherRequestObservationAtStation") 138 | .allowlist_function("SimConnect_WeatherRequestObservationAtNearestStation") 139 | .allowlist_function("SimConnect_WeatherCreateStation") 140 | .allowlist_function("SimConnect_WeatherRemoveStation") 141 | .allowlist_function("SimConnect_WeatherSetObservation") 142 | .allowlist_function("SimConnect_WeatherSetModeServer") 143 | .allowlist_function("SimConnect_WeatherSetModeTheme") 144 | .allowlist_function("SimConnect_WeatherSetModeGlobal") 145 | .allowlist_function("SimConnect_WeatherSetModeCustom") 146 | .allowlist_function("SimConnect_WeatherSetDynamicUpdateRate") 147 | .allowlist_function("SimConnect_WeatherRequestCloudState") 148 | .allowlist_function("SimConnect_WeatherCreateThermal") 149 | .allowlist_function("SimConnect_WeatherRemoveThermal") 150 | .allowlist_function("SimConnect_AICreateParkedATCAircraft") 151 | .allowlist_function("SimConnect_AICreateEnrouteATCAircraft") 152 | .allowlist_function("SimConnect_AICreateNonATCAircraft") 153 | .allowlist_function("SimConnect_AICreateSimulatedObject") 154 | .allowlist_function("SimConnect_AIReleaseControl") 155 | .allowlist_function("SimConnect_AIRemoveObject") 156 | .allowlist_function("SimConnect_AISetAircraftFlightPlan") 157 | .allowlist_function("SimConnect_ExecuteMissionAction") 158 | .allowlist_function("SimConnect_CompleteCustomMissionAction") 159 | .allowlist_function("SimConnect_Close") 160 | .allowlist_function("SimConnect_RetrieveString") 161 | .allowlist_function("SimConnect_GetLastSentPacketID") 162 | .allowlist_function("SimConnect_Open") 163 | .allowlist_function("SimConnect_CallDispatch") 164 | .allowlist_function("SimConnect_GetNextDispatch") 165 | .allowlist_function("SimConnect_RequestResponseTimes") 166 | .allowlist_function("SimConnect_InsertString") 167 | .allowlist_function("SimConnect_CameraSetRelative6DOF") 168 | .allowlist_function("SimConnect_MenuAddItem") 169 | .allowlist_function("SimConnect_MenuDeleteItem") 170 | .allowlist_function("SimConnect_MenuAddSubItem") 171 | .allowlist_function("SimConnect_MenuDeleteSubItem") 172 | .allowlist_function("SimConnect_RequestSystemState") 173 | .allowlist_function("SimConnect_SetSystemState") 174 | .allowlist_function("SimConnect_MapClientDataNameToID") 175 | .allowlist_function("SimConnect_CreateClientData") 176 | .allowlist_function("SimConnect_AddToClientDataDefinition") 177 | .allowlist_function("SimConnect_ClearClientDataDefinition") 178 | .allowlist_function("SimConnect_RequestClientData") 179 | .allowlist_function("SimConnect_SetClientData") 180 | .allowlist_function("SimConnect_FlightLoad") 181 | .allowlist_function("SimConnect_FlightSave") 182 | .allowlist_function("SimConnect_FlightPlanLoad") 183 | .allowlist_function("SimConnect_Text") 184 | .allowlist_function("SimConnect_SubscribeToFacilities") 185 | .allowlist_function("SimConnect_UnsubscribeToFacilities") 186 | .allowlist_function("SimConnect_RequestFacilitiesList") 187 | .allowlist_type("SIMCONNECT_DATA_RACE_RESULT") 188 | .allowlist_type("SIMCONNECT_DATA_INITPOSITION") 189 | .allowlist_type("SIMCONNECT_DATA_MARKERSTATE") 190 | .allowlist_type("SIMCONNECT_DATA_WAYPOINT") 191 | .allowlist_type("SIMCONNECT_DATA_LATLONALT") 192 | .allowlist_type("SIMCONNECT_DATA_XYZ") 193 | .impl_debug(true) 194 | .generate() 195 | .expect("Unable to generate bindings"); 196 | 197 | let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); 198 | bindings 199 | .write_to_file(out_path.join("bindings.rs")) 200 | .expect("Couldn't write bindings!"); 201 | } 202 | -------------------------------------------------------------------------------- /examples/aircraft_inputs/main.rs: -------------------------------------------------------------------------------- 1 | use simconnect::SIMCONNECT_CLIENT_EVENT_ID; 2 | use std::collections::HashMap; 3 | 4 | // define a struct that holds the event and the input id 5 | // the events can be found in the SimConnect SDK documentation for your sim 6 | struct Input { 7 | event: String, // The event to be triggered i.e. 8 | input_id: u32, // The id we use to trigger the event 9 | } 10 | fn main() { 11 | let input_parking_brakes = Input { 12 | event: "PARKING_BRAKES".to_string(), 13 | input_id: 1, 14 | }; 15 | let input_gear_up = Input { 16 | event: "GEAR_UP".to_string(), 17 | input_id: 2, 18 | }; 19 | let input_gear_down = Input { 20 | event: "GEAR_DOWN".to_string(), 21 | input_id: 3, 22 | }; 23 | 24 | // Define a hashmap to easily cross reference the input id with the event 25 | let mut events: HashMap = HashMap::new(); 26 | events.insert(input_parking_brakes.input_id, input_parking_brakes); 27 | events.insert(input_gear_up.input_id, input_gear_up); 28 | events.insert(input_gear_down.input_id, input_gear_down); 29 | 30 | let mut conn = simconnect::SimConnector::new(); 31 | conn.connect("Program that inputs commands to the sim"); // Initialize connection with SimConnect 32 | 33 | // loop over all the events we want to define and map them to the input id 34 | for event in &events { 35 | println!("Defining event: {}", event.1.event); 36 | println!("Input id: {}", event.1.input_id); 37 | conn.map_client_event_to_sim_event( 38 | // if input id 1 is triggered, the PARKING_BRAKES event is triggered 39 | event.1.input_id as SIMCONNECT_CLIENT_EVENT_ID, 40 | event.1.event.as_str(), 41 | ); 42 | } 43 | // loop over user input from console and trigger the corresponding events 44 | loop { 45 | println!("Enter an input id to trigger an event"); 46 | let mut input = String::new(); 47 | std::io::stdin().read_line(&mut input).unwrap(); 48 | let input_id: u32 = input.trim().parse().unwrap(); 49 | match events.get(&input_id) { 50 | // if the input id is found in the hashmap, trigger the event 51 | // otherwise print an error message 52 | Some(event) => { 53 | // this is why we've defined a hashmap instead of a vector 54 | println!("Triggering event: {}", event.event); 55 | /* send message to the sim 56 | object_id is 0 because we want to trigger the event on the user aircraft 57 | group_id is 0 because we don't want to group the event with other events 58 | priority is 0 because we don't want to prioritize the event 59 | this is used when multiple events are triggered at the same time 60 | */ 61 | conn.transmit_client_event( 62 | 0, 63 | input_id as u32, 64 | 0, 65 | simconnect::SIMCONNECT_GROUP_PRIORITY_HIGHEST, 66 | simconnect::SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY, 67 | ); 68 | } 69 | None => println!("No event found for input id: {}", input_id), 70 | } 71 | std::thread::sleep(std::time::Duration::from_millis(16)); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /examples/aircraft_updates/main.rs: -------------------------------------------------------------------------------- 1 | use std::thread::sleep; 2 | use std::time::Duration; 3 | 4 | use simconnect::DispatchResult; 5 | 6 | struct DataStruct { 7 | lat: f64, 8 | lon: f64, 9 | alt: f64, 10 | } 11 | fn main() { 12 | let mut conn = simconnect::SimConnector::new(); 13 | conn.connect("Simple Program"); // Intialize connection with SimConnect 14 | conn.add_data_definition( 15 | 0, 16 | "PLANE LATITUDE", 17 | "Degrees", 18 | simconnect::SIMCONNECT_DATATYPE_SIMCONNECT_DATATYPE_FLOAT64, 19 | u32::MAX, 20 | 0.0, 21 | ); // Assign a sim variable to a client defined id 22 | conn.add_data_definition( 23 | 0, 24 | "PLANE LONGITUDE", 25 | "Degrees", 26 | simconnect::SIMCONNECT_DATATYPE_SIMCONNECT_DATATYPE_FLOAT64, 27 | u32::MAX, 28 | 0.0, 29 | ); 30 | conn.add_data_definition( 31 | 0, 32 | "PLANE ALTITUDE", 33 | "Feet", 34 | simconnect::SIMCONNECT_DATATYPE_SIMCONNECT_DATATYPE_FLOAT64, 35 | u32::MAX, 36 | 1.0, 37 | ); //define_id, units, data_type, datum_id, epsilon (update threshold) 38 | conn.request_data_on_sim_object( 39 | 0, 40 | 0, 41 | 0, 42 | simconnect::SIMCONNECT_PERIOD_SIMCONNECT_PERIOD_SIM_FRAME, 43 | 0, 44 | 0, 45 | 0, 46 | 0, 47 | ); //request_id, define_id, object_id (user), period, falgs, origin, interval, limit - tells simconnect to send data for the defined id and on the user aircraft 48 | 49 | loop { 50 | match conn.get_next_message() { 51 | Ok(DispatchResult::SimObjectData(data)) => unsafe { 52 | if data.dwDefineID == 0 { 53 | let sim_data_ptr = std::ptr::addr_of!(data.dwData) as *const DataStruct; 54 | let sim_data_value = std::ptr::read_unaligned(sim_data_ptr); 55 | println!( 56 | "{:?} {:?} {:?}", 57 | sim_data_value.lat, sim_data_value.lon, sim_data_value.alt 58 | ); 59 | } 60 | }, 61 | Ok(DispatchResult::Open(_)) => { 62 | println!("Connected to simulator."); 63 | } 64 | Ok(DispatchResult::Quit(_)) => { 65 | println!("Disconnected from simulator."); 66 | } 67 | _ => (), 68 | } 69 | 70 | sleep(Duration::from_millis(16)); // Will use up lots of CPU if this is not included, as get_next_message() is non-blocking 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /examples/aircraft_updates_on_change/main.rs: -------------------------------------------------------------------------------- 1 | use simconnect::{DispatchResult, DWORD}; 2 | use std::thread::sleep; 3 | use std::time::Duration; 4 | 5 | // To allign the memory we have to set a fixed max size to the returned variables from the game 6 | const MAX_RETURNED_ITEMS: usize = 255; 7 | 8 | // Rust will add padding to the inner parts of a struct if it isn't marked as packed 9 | // The way Simconnect returns values is unaligned data in C style 10 | #[repr(C, packed)] 11 | struct KeyValuePairFloat { 12 | id: DWORD, 13 | value: f64, 14 | } 15 | struct DataFloatStruct { 16 | data: [KeyValuePairFloat; MAX_RETURNED_ITEMS], 17 | } 18 | #[repr(C, packed)] 19 | struct KeyValuePairString { 20 | id: DWORD, 21 | // Strings get returned as max 255 bytes 22 | value: [u8; 255], 23 | } 24 | 25 | struct DataStringStruct { 26 | data: [KeyValuePairString; MAX_RETURNED_ITEMS], 27 | } 28 | 29 | fn main() { 30 | let mut conn = simconnect::SimConnector::new(); 31 | conn.connect("Program that returns data on changes"); // Initialize connection with SimConnect 32 | 33 | // Here we define all our variable that get returned as floats 34 | // (including integers, which the memory alignment will handle) 35 | // The epsilon determines per X change do we want to receive an update from the game 36 | // This greatly reduces the amount of data send to your client 37 | // In this example the lat, lon values get an update every degree while the altitude only gets an 38 | // update every 100 feet 39 | conn.add_data_definition( 40 | 0, 41 | "PLANE LATITUDE", 42 | "Degrees", 43 | simconnect::SIMCONNECT_DATATYPE_SIMCONNECT_DATATYPE_FLOAT64, 44 | 1, 45 | 1.0, 46 | ); // Assign a sim variable to a client defined id 47 | conn.add_data_definition( 48 | 0, 49 | "PLANE LONGITUDE", 50 | "Degrees", 51 | simconnect::SIMCONNECT_DATATYPE_SIMCONNECT_DATATYPE_FLOAT64, 52 | 2, 53 | 1.0, 54 | ); 55 | conn.add_data_definition( 56 | 0, 57 | "PLANE ALTITUDE", 58 | "Feet", 59 | simconnect::SIMCONNECT_DATATYPE_SIMCONNECT_DATATYPE_FLOAT64, 60 | 3, 61 | 100.0, 62 | ); //define_id, units, data_type, datum_id, epsilon (update threshold) 63 | 64 | // Here we define all our variabes that get returned as Strings 65 | // Notice how the define_id differs from the float values 66 | // This variable returns the name of the plane found in the aircraft.cfg (max 255 characters) 67 | conn.add_data_definition( 68 | 1, 69 | "TITLE", 70 | "", 71 | simconnect::SIMCONNECT_DATATYPE_SIMCONNECT_DATATYPE_STRING256, 72 | 4, 73 | 0.0, 74 | ); 75 | 76 | // Request the data from define_id 0 (floats) and only return the value if the value has changed including the id we passed in the datum_id 77 | // So if the latitude changes we receive: key 1 value X, if the longitude changes we receive key 2 value X. 78 | // If both have changed we receive both variables in an packed array. 79 | // The amount of variables returned is defined in the data.dwDefineCount of the response 80 | conn.request_data_on_sim_object( 81 | 0, 82 | 0, 83 | 0, 84 | simconnect::SIMCONNECT_PERIOD_SIMCONNECT_PERIOD_SIM_FRAME, 85 | simconnect::SIMCONNECT_CLIENT_DATA_REQUEST_FLAG_CHANGED 86 | | simconnect::SIMCONNECT_CLIENT_DATA_REQUEST_FLAG_TAGGED, 87 | 0, 88 | 0, 89 | 0, 90 | ); //request_id, define_id, object_id (user), period, falgs, origin, interval, limit - tells simconnect to send data for the defined id and on the user aircraft 91 | // Request the data from our define_id 1 (strings) 92 | // The request_id has to differ from the float request. Or else it will overwrite the previous request 93 | conn.request_data_on_sim_object( 94 | 1, 95 | 1, 96 | 0, 97 | simconnect::SIMCONNECT_PERIOD_SIMCONNECT_PERIOD_SIM_FRAME, 98 | simconnect::SIMCONNECT_CLIENT_DATA_REQUEST_FLAG_CHANGED 99 | | simconnect::SIMCONNECT_CLIENT_DATA_REQUEST_FLAG_TAGGED, 100 | 0, 101 | 0, 102 | 0, 103 | ); //request_id, define_id, object_id (user), period, falgs, origin, interval, limit - tells simconnect to send data for the defined id and on the user aircraft 104 | 105 | loop { 106 | match conn.get_next_message() { 107 | Ok(DispatchResult::SimObjectData(data)) => unsafe { 108 | match data.dwDefineID { 109 | // Here we match the define_id we've passed using the request_data_on_sim_object 110 | 0 => { 111 | let sim_data_ptr = 112 | std::ptr::addr_of!(data.dwData) as *const DataFloatStruct; 113 | let sim_data_value = std::ptr::read_unaligned(sim_data_ptr); 114 | // The amount of floats received from the sim 115 | let count = data.dwDefineCount as usize; 116 | 117 | // iterate through the array of data structs 118 | // To align the memory we have allocated an array of 255 elements to the datastruct 119 | // The game might return 255 or 2 values 120 | // To only iterate over valid elements in the array 121 | // We are able to leverage the dwDefineCount to loop over valid elements 122 | for i in 0..count { 123 | let value = sim_data_value.data[i].value; 124 | let key = sim_data_value.data[i].id; 125 | println!("{}", key); 126 | println!("{}", value); 127 | } 128 | } 129 | 1 => { 130 | let sim_data_ptr = 131 | std::ptr::addr_of!(data.dwData) as *const DataStringStruct; 132 | // The amount of strings received from the sim 133 | let count = data.dwDefineCount as usize; 134 | let sim_data_value = std::ptr::read_unaligned(sim_data_ptr); 135 | for i in 0..count { 136 | //since we only defined 1 string variable the key returned should be 4 137 | let key = sim_data_value.data[0].id; 138 | //byte array to string 139 | let string = 140 | std::str::from_utf8(&sim_data_value.data[i].value).unwrap(); 141 | println!("{}", key); 142 | println!("{}", string); 143 | } 144 | } 145 | _ => (), 146 | } 147 | }, 148 | Ok(DispatchResult::Open(_)) => { 149 | println!("Connected to simulator."); 150 | } 151 | Ok(DispatchResult::Quit(_)) => { 152 | println!("Disconnected from simulator."); 153 | } 154 | _ => (), 155 | } 156 | 157 | sleep(Duration::from_millis(16)); // Will use up lots of CPU if this is not included, as get_next_message() is non-blocking 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /libsrc/include/SimConnect.hpp: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // Copyright (c) Microsoft Corporation. All Rights Reserved. 4 | // 5 | //----------------------------------------------------------------------------- 6 | 7 | #include 8 | 9 | #ifndef _SIMCONNECT_H_ 10 | #define _SIMCONNECT_H_ 11 | 12 | #pragma once 13 | 14 | #ifdef _MSFS_WASM 15 | #ifndef SIMCONNECT_WASM_MODULE 16 | #define SIMCONNECT_WASM_MODULE "env" 17 | #endif 18 | #endif 19 | 20 | #ifndef DWORD_MAX 21 | #define DWORD_MAX 0xFFFFFFFF 22 | #endif 23 | 24 | #include 25 | 26 | typedef DWORD SIMCONNECT_OBJECT_ID; 27 | 28 | //---------------------------------------------------------------------------- 29 | // Constants 30 | //---------------------------------------------------------------------------- 31 | 32 | static const DWORD SIMCONNECT_UNUSED = DWORD_MAX; // special value to indicate unused event, ID 33 | static const DWORD SIMCONNECT_OBJECT_ID_USER = 0; // proxy value for User vehicle ObjectID 34 | 35 | static const float SIMCONNECT_CAMERA_IGNORE_FIELD = FLT_MAX; //Used to tell the Camera API to NOT modify the value in this part of the argument. 36 | 37 | static const DWORD SIMCONNECT_CLIENTDATA_MAX_SIZE = 8192; // maximum value for SimConnect_CreateClientData dwSize parameter 38 | 39 | 40 | // Notification Group priority values 41 | static const DWORD SIMCONNECT_GROUP_PRIORITY_HIGHEST = 1; // highest priority 42 | static const DWORD SIMCONNECT_GROUP_PRIORITY_HIGHEST_MASKABLE = 10000000; // highest priority that allows events to be masked 43 | static const DWORD SIMCONNECT_GROUP_PRIORITY_STANDARD = 1900000000; // standard priority 44 | static const DWORD SIMCONNECT_GROUP_PRIORITY_DEFAULT = 2000000000; // default priority 45 | static const DWORD SIMCONNECT_GROUP_PRIORITY_LOWEST = 4000000000; // priorities lower than this will be ignored 46 | 47 | //Weather observations Metar strings 48 | static const DWORD MAX_METAR_LENGTH = 2000; 49 | 50 | // Maximum thermal size is 100 km. 51 | static const float MAX_THERMAL_SIZE = 100000; 52 | static const float MAX_THERMAL_RATE = 1000; 53 | 54 | // SIMCONNECT_DATA_INITPOSITION.Airspeed 55 | static const DWORD INITPOSITION_AIRSPEED_CRUISE = -1; // aircraft's cruise airspeed 56 | static const DWORD INITPOSITION_AIRSPEED_KEEP = -2; // keep current airspeed 57 | 58 | // AddToClientDataDefinition dwSizeOrType parameter type values 59 | static const DWORD SIMCONNECT_CLIENTDATATYPE_INT8 = -1; // 8-bit integer number 60 | static const DWORD SIMCONNECT_CLIENTDATATYPE_INT16 = -2; // 16-bit integer number 61 | static const DWORD SIMCONNECT_CLIENTDATATYPE_INT32 = -3; // 32-bit integer number 62 | static const DWORD SIMCONNECT_CLIENTDATATYPE_INT64 = -4; // 64-bit integer number 63 | static const DWORD SIMCONNECT_CLIENTDATATYPE_FLOAT32 = -5; // 32-bit floating-point number (float) 64 | static const DWORD SIMCONNECT_CLIENTDATATYPE_FLOAT64 = -6; // 64-bit floating-point number (double) 65 | 66 | // AddToClientDataDefinition dwOffset parameter special values 67 | static const DWORD SIMCONNECT_CLIENTDATAOFFSET_AUTO = -1; // automatically compute offset of the ClientData variable 68 | 69 | // Open ConfigIndex parameter special value 70 | static const DWORD SIMCONNECT_OPEN_CONFIGINDEX_LOCAL = -1; // ignore SimConnect.cfg settings, and force local connection 71 | 72 | //---------------------------------------------------------------------------- 73 | // Enum definitions 74 | //---------------------------------------------------------------------------- 75 | 76 | //these came from substituteMacros 77 | #define SIMCONNECT_REFSTRUCT struct 78 | #define SIMCONNECT_STRUCT struct 79 | #define SIMCONNECT_STRING(name, size) char name[size] 80 | #define SIMCONNECT_GUID GUID 81 | #define SIMCONNECT_STRINGV(name) char name[1] 82 | #define SIMCONNECT_DATAV(name, id, count) DWORD name 83 | #define SIMCONNECT_FIXEDTYPE_DATAV(type, name, count, cliMarshalAs, cliType) type name[1] 84 | #define SIMCONNECT_GUID GUID 85 | #define SIMCONNECT_ENUM enum 86 | #define SIMCONNECT_ENUM_FLAGS typedef DWORD 87 | #define SIMCONNECT_USER_ENUM typedef DWORD 88 | 89 | 90 | // Receive data types 91 | SIMCONNECT_ENUM SIMCONNECT_RECV_ID { 92 | SIMCONNECT_RECV_ID_NULL, 93 | SIMCONNECT_RECV_ID_EXCEPTION, 94 | SIMCONNECT_RECV_ID_OPEN, 95 | SIMCONNECT_RECV_ID_QUIT, 96 | SIMCONNECT_RECV_ID_EVENT, 97 | SIMCONNECT_RECV_ID_EVENT_OBJECT_ADDREMOVE, 98 | SIMCONNECT_RECV_ID_EVENT_FILENAME, 99 | SIMCONNECT_RECV_ID_EVENT_FRAME, 100 | SIMCONNECT_RECV_ID_SIMOBJECT_DATA, 101 | SIMCONNECT_RECV_ID_SIMOBJECT_DATA_BYTYPE, 102 | SIMCONNECT_RECV_ID_WEATHER_OBSERVATION, 103 | SIMCONNECT_RECV_ID_CLOUD_STATE, 104 | SIMCONNECT_RECV_ID_ASSIGNED_OBJECT_ID, 105 | SIMCONNECT_RECV_ID_RESERVED_KEY, 106 | SIMCONNECT_RECV_ID_CUSTOM_ACTION, 107 | SIMCONNECT_RECV_ID_SYSTEM_STATE, 108 | SIMCONNECT_RECV_ID_CLIENT_DATA, 109 | SIMCONNECT_RECV_ID_EVENT_WEATHER_MODE, 110 | SIMCONNECT_RECV_ID_AIRPORT_LIST, 111 | SIMCONNECT_RECV_ID_VOR_LIST, 112 | SIMCONNECT_RECV_ID_NDB_LIST, 113 | SIMCONNECT_RECV_ID_WAYPOINT_LIST, 114 | SIMCONNECT_RECV_ID_EVENT_MULTIPLAYER_SERVER_STARTED, 115 | SIMCONNECT_RECV_ID_EVENT_MULTIPLAYER_CLIENT_STARTED, 116 | SIMCONNECT_RECV_ID_EVENT_MULTIPLAYER_SESSION_ENDED, 117 | SIMCONNECT_RECV_ID_EVENT_RACE_END, 118 | SIMCONNECT_RECV_ID_EVENT_RACE_LAP, 119 | #ifdef ENABLE_SIMCONNECT_EXPERIMENTAL 120 | SIMCONNECT_RECV_ID_PICK, 121 | #endif //ENABLE_SIMCONNECT_EXPERIMENTAL 122 | }; 123 | 124 | 125 | 126 | // Data data types 127 | SIMCONNECT_ENUM SIMCONNECT_DATATYPE { 128 | SIMCONNECT_DATATYPE_INVALID, // invalid data type 129 | SIMCONNECT_DATATYPE_INT32, // 32-bit integer number 130 | SIMCONNECT_DATATYPE_INT64, // 64-bit integer number 131 | SIMCONNECT_DATATYPE_FLOAT32, // 32-bit floating-point number (float) 132 | SIMCONNECT_DATATYPE_FLOAT64, // 64-bit floating-point number (double) 133 | SIMCONNECT_DATATYPE_STRING8, // 8-byte string 134 | SIMCONNECT_DATATYPE_STRING32, // 32-byte string 135 | SIMCONNECT_DATATYPE_STRING64, // 64-byte string 136 | SIMCONNECT_DATATYPE_STRING128, // 128-byte string 137 | SIMCONNECT_DATATYPE_STRING256, // 256-byte string 138 | SIMCONNECT_DATATYPE_STRING260, // 260-byte string 139 | SIMCONNECT_DATATYPE_STRINGV, // variable-length string 140 | 141 | SIMCONNECT_DATATYPE_INITPOSITION, // see SIMCONNECT_DATA_INITPOSITION 142 | SIMCONNECT_DATATYPE_MARKERSTATE, // see SIMCONNECT_DATA_MARKERSTATE 143 | SIMCONNECT_DATATYPE_WAYPOINT, // see SIMCONNECT_DATA_WAYPOINT 144 | SIMCONNECT_DATATYPE_LATLONALT, // see SIMCONNECT_DATA_LATLONALT 145 | SIMCONNECT_DATATYPE_XYZ, // see SIMCONNECT_DATA_XYZ 146 | 147 | SIMCONNECT_DATATYPE_MAX // enum limit 148 | }; 149 | 150 | // Exception error types 151 | SIMCONNECT_ENUM SIMCONNECT_EXCEPTION { 152 | SIMCONNECT_EXCEPTION_NONE, 153 | 154 | SIMCONNECT_EXCEPTION_ERROR, 155 | SIMCONNECT_EXCEPTION_SIZE_MISMATCH, 156 | SIMCONNECT_EXCEPTION_UNRECOGNIZED_ID, 157 | SIMCONNECT_EXCEPTION_UNOPENED, 158 | SIMCONNECT_EXCEPTION_VERSION_MISMATCH, 159 | SIMCONNECT_EXCEPTION_TOO_MANY_GROUPS, 160 | SIMCONNECT_EXCEPTION_NAME_UNRECOGNIZED, 161 | SIMCONNECT_EXCEPTION_TOO_MANY_EVENT_NAMES, 162 | SIMCONNECT_EXCEPTION_EVENT_ID_DUPLICATE, 163 | SIMCONNECT_EXCEPTION_TOO_MANY_MAPS, 164 | SIMCONNECT_EXCEPTION_TOO_MANY_OBJECTS, 165 | SIMCONNECT_EXCEPTION_TOO_MANY_REQUESTS, 166 | SIMCONNECT_EXCEPTION_WEATHER_INVALID_PORT, 167 | SIMCONNECT_EXCEPTION_WEATHER_INVALID_METAR, 168 | SIMCONNECT_EXCEPTION_WEATHER_UNABLE_TO_GET_OBSERVATION, 169 | SIMCONNECT_EXCEPTION_WEATHER_UNABLE_TO_CREATE_STATION, 170 | SIMCONNECT_EXCEPTION_WEATHER_UNABLE_TO_REMOVE_STATION, 171 | SIMCONNECT_EXCEPTION_INVALID_DATA_TYPE, 172 | SIMCONNECT_EXCEPTION_INVALID_DATA_SIZE, 173 | SIMCONNECT_EXCEPTION_DATA_ERROR, 174 | SIMCONNECT_EXCEPTION_INVALID_ARRAY, 175 | SIMCONNECT_EXCEPTION_CREATE_OBJECT_FAILED, 176 | SIMCONNECT_EXCEPTION_LOAD_FLIGHTPLAN_FAILED, 177 | SIMCONNECT_EXCEPTION_OPERATION_INVALID_FOR_OBJECT_TYPE, 178 | SIMCONNECT_EXCEPTION_ILLEGAL_OPERATION, 179 | SIMCONNECT_EXCEPTION_ALREADY_SUBSCRIBED, 180 | SIMCONNECT_EXCEPTION_INVALID_ENUM, 181 | SIMCONNECT_EXCEPTION_DEFINITION_ERROR, 182 | SIMCONNECT_EXCEPTION_DUPLICATE_ID, 183 | SIMCONNECT_EXCEPTION_DATUM_ID, 184 | SIMCONNECT_EXCEPTION_OUT_OF_BOUNDS, 185 | SIMCONNECT_EXCEPTION_ALREADY_CREATED, 186 | SIMCONNECT_EXCEPTION_OBJECT_OUTSIDE_REALITY_BUBBLE, 187 | SIMCONNECT_EXCEPTION_OBJECT_CONTAINER, 188 | SIMCONNECT_EXCEPTION_OBJECT_AI, 189 | SIMCONNECT_EXCEPTION_OBJECT_ATC, 190 | SIMCONNECT_EXCEPTION_OBJECT_SCHEDULE, 191 | }; 192 | 193 | // Object types 194 | SIMCONNECT_ENUM SIMCONNECT_SIMOBJECT_TYPE { 195 | SIMCONNECT_SIMOBJECT_TYPE_USER, 196 | SIMCONNECT_SIMOBJECT_TYPE_ALL, 197 | SIMCONNECT_SIMOBJECT_TYPE_AIRCRAFT, 198 | SIMCONNECT_SIMOBJECT_TYPE_HELICOPTER, 199 | SIMCONNECT_SIMOBJECT_TYPE_BOAT, 200 | SIMCONNECT_SIMOBJECT_TYPE_GROUND, 201 | }; 202 | 203 | // EventState values 204 | SIMCONNECT_ENUM SIMCONNECT_STATE { 205 | SIMCONNECT_STATE_OFF, 206 | SIMCONNECT_STATE_ON, 207 | }; 208 | 209 | // Object Data Request Period values 210 | SIMCONNECT_ENUM SIMCONNECT_PERIOD { 211 | SIMCONNECT_PERIOD_NEVER, 212 | SIMCONNECT_PERIOD_ONCE, 213 | SIMCONNECT_PERIOD_VISUAL_FRAME, 214 | SIMCONNECT_PERIOD_SIM_FRAME, 215 | SIMCONNECT_PERIOD_SECOND, 216 | }; 217 | 218 | 219 | SIMCONNECT_ENUM SIMCONNECT_MISSION_END { 220 | SIMCONNECT_MISSION_FAILED, 221 | SIMCONNECT_MISSION_CRASHED, 222 | SIMCONNECT_MISSION_SUCCEEDED 223 | }; 224 | 225 | // ClientData Request Period values 226 | SIMCONNECT_ENUM SIMCONNECT_CLIENT_DATA_PERIOD { 227 | SIMCONNECT_CLIENT_DATA_PERIOD_NEVER, 228 | SIMCONNECT_CLIENT_DATA_PERIOD_ONCE, 229 | SIMCONNECT_CLIENT_DATA_PERIOD_VISUAL_FRAME, 230 | SIMCONNECT_CLIENT_DATA_PERIOD_ON_SET, 231 | SIMCONNECT_CLIENT_DATA_PERIOD_SECOND, 232 | }; 233 | 234 | SIMCONNECT_ENUM SIMCONNECT_TEXT_TYPE { 235 | SIMCONNECT_TEXT_TYPE_SCROLL_BLACK, 236 | SIMCONNECT_TEXT_TYPE_SCROLL_WHITE, 237 | SIMCONNECT_TEXT_TYPE_SCROLL_RED, 238 | SIMCONNECT_TEXT_TYPE_SCROLL_GREEN, 239 | SIMCONNECT_TEXT_TYPE_SCROLL_BLUE, 240 | SIMCONNECT_TEXT_TYPE_SCROLL_YELLOW, 241 | SIMCONNECT_TEXT_TYPE_SCROLL_MAGENTA, 242 | SIMCONNECT_TEXT_TYPE_SCROLL_CYAN, 243 | SIMCONNECT_TEXT_TYPE_PRINT_BLACK=0x0100, 244 | SIMCONNECT_TEXT_TYPE_PRINT_WHITE, 245 | SIMCONNECT_TEXT_TYPE_PRINT_RED, 246 | SIMCONNECT_TEXT_TYPE_PRINT_GREEN, 247 | SIMCONNECT_TEXT_TYPE_PRINT_BLUE, 248 | SIMCONNECT_TEXT_TYPE_PRINT_YELLOW, 249 | SIMCONNECT_TEXT_TYPE_PRINT_MAGENTA, 250 | SIMCONNECT_TEXT_TYPE_PRINT_CYAN, 251 | SIMCONNECT_TEXT_TYPE_MENU=0x0200, 252 | }; 253 | 254 | SIMCONNECT_ENUM SIMCONNECT_TEXT_RESULT { 255 | SIMCONNECT_TEXT_RESULT_MENU_SELECT_1, 256 | SIMCONNECT_TEXT_RESULT_MENU_SELECT_2, 257 | SIMCONNECT_TEXT_RESULT_MENU_SELECT_3, 258 | SIMCONNECT_TEXT_RESULT_MENU_SELECT_4, 259 | SIMCONNECT_TEXT_RESULT_MENU_SELECT_5, 260 | SIMCONNECT_TEXT_RESULT_MENU_SELECT_6, 261 | SIMCONNECT_TEXT_RESULT_MENU_SELECT_7, 262 | SIMCONNECT_TEXT_RESULT_MENU_SELECT_8, 263 | SIMCONNECT_TEXT_RESULT_MENU_SELECT_9, 264 | SIMCONNECT_TEXT_RESULT_MENU_SELECT_10, 265 | SIMCONNECT_TEXT_RESULT_DISPLAYED = 0x00010000, 266 | SIMCONNECT_TEXT_RESULT_QUEUED, 267 | SIMCONNECT_TEXT_RESULT_REMOVED, 268 | SIMCONNECT_TEXT_RESULT_REPLACED, 269 | SIMCONNECT_TEXT_RESULT_TIMEOUT, 270 | }; 271 | 272 | SIMCONNECT_ENUM SIMCONNECT_WEATHER_MODE { 273 | SIMCONNECT_WEATHER_MODE_THEME, 274 | SIMCONNECT_WEATHER_MODE_RWW, 275 | SIMCONNECT_WEATHER_MODE_CUSTOM, 276 | SIMCONNECT_WEATHER_MODE_GLOBAL, 277 | }; 278 | 279 | SIMCONNECT_ENUM SIMCONNECT_FACILITY_LIST_TYPE { 280 | SIMCONNECT_FACILITY_LIST_TYPE_AIRPORT, 281 | SIMCONNECT_FACILITY_LIST_TYPE_WAYPOINT, 282 | SIMCONNECT_FACILITY_LIST_TYPE_NDB, 283 | SIMCONNECT_FACILITY_LIST_TYPE_VOR, 284 | SIMCONNECT_FACILITY_LIST_TYPE_COUNT // invalid 285 | }; 286 | 287 | 288 | SIMCONNECT_ENUM_FLAGS SIMCONNECT_VOR_FLAGS; // flags for SIMCONNECT_RECV_ID_VOR_LIST 289 | static const DWORD SIMCONNECT_RECV_ID_VOR_LIST_HAS_NAV_SIGNAL = 0x00000001; // Has Nav signal 290 | static const DWORD SIMCONNECT_RECV_ID_VOR_LIST_HAS_LOCALIZER = 0x00000002; // Has localizer 291 | static const DWORD SIMCONNECT_RECV_ID_VOR_LIST_HAS_GLIDE_SLOPE = 0x00000004; // Has Nav signal 292 | static const DWORD SIMCONNECT_RECV_ID_VOR_LIST_HAS_DME = 0x00000008; // Station has DME 293 | 294 | 295 | 296 | // bits for the Waypoint Flags field: may be combined 297 | SIMCONNECT_ENUM_FLAGS SIMCONNECT_WAYPOINT_FLAGS; 298 | static const DWORD SIMCONNECT_WAYPOINT_NONE = 0x00; 299 | static const DWORD SIMCONNECT_WAYPOINT_SPEED_REQUESTED = 0x04; // requested speed at waypoint is valid 300 | static const DWORD SIMCONNECT_WAYPOINT_THROTTLE_REQUESTED = 0x08; // request a specific throttle percentage 301 | static const DWORD SIMCONNECT_WAYPOINT_COMPUTE_VERTICAL_SPEED = 0x10; // compute vertical to speed to reach waypoint altitude when crossing the waypoint 302 | static const DWORD SIMCONNECT_WAYPOINT_ALTITUDE_IS_AGL = 0x20; // AltitudeIsAGL 303 | static const DWORD SIMCONNECT_WAYPOINT_ON_GROUND = 0x00100000; // place this waypoint on the ground 304 | static const DWORD SIMCONNECT_WAYPOINT_REVERSE = 0x00200000; // Back up to this waypoint. Only valid on first waypoint 305 | static const DWORD SIMCONNECT_WAYPOINT_WRAP_TO_FIRST = 0x00400000; // Wrap around back to first waypoint. Only valid on last waypoint. 306 | 307 | SIMCONNECT_ENUM_FLAGS SIMCONNECT_EVENT_FLAG; 308 | static const DWORD SIMCONNECT_EVENT_FLAG_DEFAULT = 0x00000000; 309 | static const DWORD SIMCONNECT_EVENT_FLAG_FAST_REPEAT_TIMER = 0x00000001; // set event repeat timer to simulate fast repeat 310 | static const DWORD SIMCONNECT_EVENT_FLAG_SLOW_REPEAT_TIMER = 0x00000002; // set event repeat timer to simulate slow repeat 311 | static const DWORD SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY = 0x00000010; // interpret GroupID parameter as priority value 312 | 313 | SIMCONNECT_ENUM_FLAGS SIMCONNECT_DATA_REQUEST_FLAG; 314 | static const DWORD SIMCONNECT_DATA_REQUEST_FLAG_DEFAULT = 0x00000000; 315 | static const DWORD SIMCONNECT_DATA_REQUEST_FLAG_CHANGED = 0x00000001; // send requested data when value(s) change 316 | static const DWORD SIMCONNECT_DATA_REQUEST_FLAG_TAGGED = 0x00000002; // send requested data in tagged format 317 | 318 | SIMCONNECT_ENUM_FLAGS SIMCONNECT_DATA_SET_FLAG; 319 | static const DWORD SIMCONNECT_DATA_SET_FLAG_DEFAULT = 0x00000000; 320 | static const DWORD SIMCONNECT_DATA_SET_FLAG_TAGGED = 0x00000001; // data is in tagged format 321 | 322 | SIMCONNECT_ENUM_FLAGS SIMCONNECT_CREATE_CLIENT_DATA_FLAG; 323 | static const DWORD SIMCONNECT_CREATE_CLIENT_DATA_FLAG_DEFAULT = 0x00000000; 324 | static const DWORD SIMCONNECT_CREATE_CLIENT_DATA_FLAG_READ_ONLY = 0x00000001; // permit only ClientData creator to write into ClientData 325 | 326 | 327 | SIMCONNECT_ENUM_FLAGS SIMCONNECT_CLIENT_DATA_REQUEST_FLAG; 328 | static const DWORD SIMCONNECT_CLIENT_DATA_REQUEST_FLAG_DEFAULT = 0x00000000; 329 | static const DWORD SIMCONNECT_CLIENT_DATA_REQUEST_FLAG_CHANGED = 0x00000001; // send requested ClientData when value(s) change 330 | static const DWORD SIMCONNECT_CLIENT_DATA_REQUEST_FLAG_TAGGED = 0x00000002; // send requested ClientData in tagged format 331 | 332 | SIMCONNECT_ENUM_FLAGS SIMCONNECT_CLIENT_DATA_SET_FLAG; 333 | static const DWORD SIMCONNECT_CLIENT_DATA_SET_FLAG_DEFAULT = 0x00000000; 334 | static const DWORD SIMCONNECT_CLIENT_DATA_SET_FLAG_TAGGED = 0x00000001; // data is in tagged format 335 | 336 | 337 | SIMCONNECT_ENUM_FLAGS SIMCONNECT_VIEW_SYSTEM_EVENT_DATA; // dwData contains these flags for the "View" System Event 338 | static const DWORD SIMCONNECT_VIEW_SYSTEM_EVENT_DATA_COCKPIT_2D = 0x00000001; // 2D Panels in cockpit view 339 | static const DWORD SIMCONNECT_VIEW_SYSTEM_EVENT_DATA_COCKPIT_VIRTUAL = 0x00000002; // Virtual (3D) panels in cockpit view 340 | static const DWORD SIMCONNECT_VIEW_SYSTEM_EVENT_DATA_ORTHOGONAL = 0x00000004; // Orthogonal (Map) view 341 | 342 | SIMCONNECT_ENUM_FLAGS SIMCONNECT_SOUND_SYSTEM_EVENT_DATA; // dwData contains these flags for the "Sound" System Event 343 | static const DWORD SIMCONNECT_SOUND_SYSTEM_EVENT_DATA_MASTER = 0x00000001; // Sound Master 344 | 345 | 346 | #ifdef ENABLE_SIMCONNECT_EXPERIMENTAL 347 | 348 | SIMCONNECT_ENUM_FLAGS SIMCONNECT_PICK_FLAGS 349 | { 350 | SIMCONNECT_PICK_GROUND = 0x01, // pick ground/ pick result item is ground location 351 | SIMCONNECT_PICK_AI = 0x02, // pick AI / pick result item is AI, (dwSimObjectID is valid) 352 | SIMCONNECT_PICK_SCENERY = 0x04, // pick scenery/ pick result item is scenery object (hSceneryObject is valid) 353 | SIMCONNECT_PICK_ALL = SIMCONNECT_PICK_SCENERY | SIMCONNECT_PICK_AI | SIMCONNECT_PICK_GROUND, // pick all / (not valid on pick result item) 354 | SIMCONNECT_PICK_COORDSASPIXELS = 0x08, 355 | }; 356 | 357 | #endif //ENABLE_SIMCONNECT_EXPERIMENTAL 358 | 359 | //---------------------------------------------------------------------------- 360 | // User-defined enums 361 | //---------------------------------------------------------------------------- 362 | 363 | SIMCONNECT_USER_ENUM SIMCONNECT_NOTIFICATION_GROUP_ID; //client-defined notification group ID 364 | SIMCONNECT_USER_ENUM SIMCONNECT_INPUT_GROUP_ID; //client-defined input group ID 365 | SIMCONNECT_USER_ENUM SIMCONNECT_DATA_DEFINITION_ID; //client-defined data definition ID 366 | SIMCONNECT_USER_ENUM SIMCONNECT_DATA_REQUEST_ID; //client-defined request data ID 367 | 368 | SIMCONNECT_USER_ENUM SIMCONNECT_CLIENT_EVENT_ID; //client-defined client event ID 369 | SIMCONNECT_USER_ENUM SIMCONNECT_CLIENT_DATA_ID; //client-defined client data ID 370 | SIMCONNECT_USER_ENUM SIMCONNECT_CLIENT_DATA_DEFINITION_ID; //client-defined client data definition ID 371 | 372 | 373 | //---------------------------------------------------------------------------- 374 | // Struct definitions 375 | //---------------------------------------------------------------------------- 376 | 377 | #pragma pack(push, 1) 378 | 379 | SIMCONNECT_REFSTRUCT SIMCONNECT_RECV 380 | { 381 | DWORD dwSize; // record size 382 | DWORD dwVersion; // interface version 383 | DWORD dwID; // see SIMCONNECT_RECV_ID 384 | }; 385 | 386 | SIMCONNECT_REFSTRUCT SIMCONNECT_RECV_EXCEPTION : public SIMCONNECT_RECV // when dwID == SIMCONNECT_RECV_ID_EXCEPTION 387 | { 388 | DWORD dwException; // see SIMCONNECT_EXCEPTION 389 | static const DWORD UNKNOWN_SENDID = 0; 390 | DWORD dwSendID; // see SimConnect_GetLastSentPacketID 391 | static const DWORD UNKNOWN_INDEX = DWORD_MAX; 392 | DWORD dwIndex; // index of parameter that was source of error 393 | }; 394 | 395 | SIMCONNECT_REFSTRUCT SIMCONNECT_RECV_OPEN : public SIMCONNECT_RECV // when dwID == SIMCONNECT_RECV_ID_OPEN 396 | { 397 | SIMCONNECT_STRING( szApplicationName, 256); 398 | DWORD dwApplicationVersionMajor; 399 | DWORD dwApplicationVersionMinor; 400 | DWORD dwApplicationBuildMajor; 401 | DWORD dwApplicationBuildMinor; 402 | DWORD dwSimConnectVersionMajor; 403 | DWORD dwSimConnectVersionMinor; 404 | DWORD dwSimConnectBuildMajor; 405 | DWORD dwSimConnectBuildMinor; 406 | DWORD dwReserved1; 407 | DWORD dwReserved2; 408 | }; 409 | 410 | SIMCONNECT_REFSTRUCT SIMCONNECT_RECV_QUIT : public SIMCONNECT_RECV // when dwID == SIMCONNECT_RECV_ID_QUIT 411 | { 412 | }; 413 | 414 | SIMCONNECT_REFSTRUCT SIMCONNECT_RECV_EVENT : public SIMCONNECT_RECV // when dwID == SIMCONNECT_RECV_ID_EVENT 415 | { 416 | static const DWORD UNKNOWN_GROUP = DWORD_MAX; 417 | DWORD uGroupID; 418 | DWORD uEventID; 419 | DWORD dwData; // uEventID-dependent context 420 | }; 421 | 422 | SIMCONNECT_REFSTRUCT SIMCONNECT_RECV_EVENT_FILENAME : public SIMCONNECT_RECV_EVENT // when dwID == SIMCONNECT_RECV_ID_EVENT_FILENAME 423 | { 424 | SIMCONNECT_STRING( szFileName, MAX_PATH); // uEventID-dependent context 425 | DWORD dwFlags; 426 | }; 427 | 428 | SIMCONNECT_REFSTRUCT SIMCONNECT_RECV_EVENT_OBJECT_ADDREMOVE : public SIMCONNECT_RECV_EVENT // when dwID == SIMCONNECT_RECV_ID_EVENT_FILENAME 429 | { 430 | SIMCONNECT_SIMOBJECT_TYPE eObjType; 431 | }; 432 | 433 | SIMCONNECT_REFSTRUCT SIMCONNECT_RECV_EVENT_FRAME : public SIMCONNECT_RECV_EVENT // when dwID == SIMCONNECT_RECV_ID_EVENT_FRAME 434 | { 435 | float fFrameRate; 436 | float fSimSpeed; 437 | }; 438 | 439 | SIMCONNECT_REFSTRUCT SIMCONNECT_RECV_EVENT_MULTIPLAYER_SERVER_STARTED : public SIMCONNECT_RECV_EVENT // when dwID == SIMCONNECT_RECV_ID_EVENT_MULTIPLAYER_SERVER_STARTED 440 | { 441 | // No event specific data, for now 442 | }; 443 | 444 | SIMCONNECT_REFSTRUCT SIMCONNECT_RECV_EVENT_MULTIPLAYER_CLIENT_STARTED : public SIMCONNECT_RECV_EVENT // when dwID == SIMCONNECT_RECV_ID_EVENT_MULTIPLAYER_CLIENT_STARTED 445 | { 446 | // No event specific data, for now 447 | }; 448 | 449 | SIMCONNECT_REFSTRUCT SIMCONNECT_RECV_EVENT_MULTIPLAYER_SESSION_ENDED : public SIMCONNECT_RECV_EVENT // when dwID == SIMCONNECT_RECV_ID_EVENT_MULTIPLAYER_SESSION_ENDED 450 | { 451 | // No event specific data, for now 452 | }; 453 | 454 | // SIMCONNECT_DATA_RACE_RESULT 455 | SIMCONNECT_STRUCT SIMCONNECT_DATA_RACE_RESULT 456 | { 457 | DWORD dwNumberOfRacers; // The total number of racers 458 | SIMCONNECT_GUID MissionGUID; // The name of the mission to execute, NULL if no mission 459 | SIMCONNECT_STRING( szPlayerName, MAX_PATH); // The name of the player 460 | SIMCONNECT_STRING( szSessionType, MAX_PATH); // The type of the multiplayer session: "LAN", "GAMESPY") 461 | SIMCONNECT_STRING( szAircraft, MAX_PATH); // The aircraft type 462 | SIMCONNECT_STRING( szPlayerRole, MAX_PATH); // The player role in the mission 463 | double fTotalTime; // Total time in seconds, 0 means DNF 464 | double fPenaltyTime; // Total penalty time in seconds 465 | DWORD dwIsDisqualified; // non 0 - disqualified, 0 - not disqualified 466 | }; 467 | 468 | SIMCONNECT_REFSTRUCT SIMCONNECT_RECV_EVENT_RACE_END : public SIMCONNECT_RECV_EVENT // when dwID == SIMCONNECT_RECV_ID_EVENT_RACE_END 469 | { 470 | DWORD dwRacerNumber; // The index of the racer the results are for 471 | SIMCONNECT_DATA_RACE_RESULT RacerData; 472 | }; 473 | 474 | SIMCONNECT_REFSTRUCT SIMCONNECT_RECV_EVENT_RACE_LAP : public SIMCONNECT_RECV_EVENT // when dwID == SIMCONNECT_RECV_ID_EVENT_RACE_LAP 475 | { 476 | DWORD dwLapIndex; // The index of the lap the results are for 477 | SIMCONNECT_DATA_RACE_RESULT RacerData; 478 | }; 479 | 480 | SIMCONNECT_REFSTRUCT SIMCONNECT_RECV_SIMOBJECT_DATA : public SIMCONNECT_RECV // when dwID == SIMCONNECT_RECV_ID_SIMOBJECT_DATA 481 | { 482 | DWORD dwRequestID; 483 | DWORD dwObjectID; 484 | DWORD dwDefineID; 485 | DWORD dwFlags; // SIMCONNECT_DATA_REQUEST_FLAG 486 | DWORD dwentrynumber; // if multiple objects returned, this is number out of . 487 | DWORD dwoutof; // note: starts with 1, not 0. 488 | DWORD dwDefineCount; // data count (number of datums, *not* byte count) 489 | SIMCONNECT_DATAV( dwData, dwDefineID, ); // data begins here, dwDefineCount data items 490 | }; 491 | 492 | SIMCONNECT_REFSTRUCT SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE : public SIMCONNECT_RECV_SIMOBJECT_DATA // when dwID == SIMCONNECT_RECV_ID_SIMOBJECT_DATA_BYTYPE 493 | { 494 | }; 495 | 496 | SIMCONNECT_REFSTRUCT SIMCONNECT_RECV_CLIENT_DATA : public SIMCONNECT_RECV_SIMOBJECT_DATA // when dwID == SIMCONNECT_RECV_ID_CLIENT_DATA 497 | { 498 | }; 499 | 500 | SIMCONNECT_REFSTRUCT SIMCONNECT_RECV_WEATHER_OBSERVATION : public SIMCONNECT_RECV // when dwID == SIMCONNECT_RECV_ID_WEATHER_OBSERVATION 501 | { 502 | DWORD dwRequestID; 503 | SIMCONNECT_STRINGV( szMetar); // Variable length string whose maximum size is MAX_METAR_LENGTH 504 | }; 505 | 506 | static const int SIMCONNECT_CLOUD_STATE_ARRAY_WIDTH = 64; 507 | static const int SIMCONNECT_CLOUD_STATE_ARRAY_SIZE = SIMCONNECT_CLOUD_STATE_ARRAY_WIDTH*SIMCONNECT_CLOUD_STATE_ARRAY_WIDTH; 508 | 509 | SIMCONNECT_REFSTRUCT SIMCONNECT_RECV_CLOUD_STATE : public SIMCONNECT_RECV // when dwID == SIMCONNECT_RECV_ID_CLOUD_STATE 510 | { 511 | DWORD dwRequestID; 512 | DWORD dwArraySize; 513 | SIMCONNECT_FIXEDTYPE_DATAV(BYTE, rgbData, dwArraySize, U1 /*member of UnmanagedType enum*/ , System::Byte /*cli type*/); 514 | }; 515 | 516 | SIMCONNECT_REFSTRUCT SIMCONNECT_RECV_ASSIGNED_OBJECT_ID : public SIMCONNECT_RECV // when dwID == SIMCONNECT_RECV_ID_ASSIGNED_OBJECT_ID 517 | { 518 | DWORD dwRequestID; 519 | DWORD dwObjectID; 520 | }; 521 | 522 | SIMCONNECT_REFSTRUCT SIMCONNECT_RECV_RESERVED_KEY : public SIMCONNECT_RECV // when dwID == SIMCONNECT_RECV_ID_RESERVED_KEY 523 | { 524 | SIMCONNECT_STRING( szChoiceReserved, 30); 525 | SIMCONNECT_STRING( szReservedKey, 50); 526 | }; 527 | 528 | SIMCONNECT_REFSTRUCT SIMCONNECT_RECV_SYSTEM_STATE : public SIMCONNECT_RECV // when dwID == SIMCONNECT_RECV_ID_SYSTEM_STATE 529 | { 530 | DWORD dwRequestID; 531 | DWORD dwInteger; 532 | float fFloat; 533 | SIMCONNECT_STRING( szString, MAX_PATH); 534 | }; 535 | 536 | SIMCONNECT_REFSTRUCT SIMCONNECT_RECV_CUSTOM_ACTION : public SIMCONNECT_RECV_EVENT 537 | { 538 | SIMCONNECT_GUID guidInstanceId; // Instance id of the action that executed 539 | DWORD dwWaitForCompletion; // Wait for completion flag on the action 540 | SIMCONNECT_STRINGV( szPayLoad); // Variable length string payload associated with the mission action. 541 | }; 542 | 543 | SIMCONNECT_REFSTRUCT SIMCONNECT_RECV_EVENT_WEATHER_MODE : public SIMCONNECT_RECV_EVENT 544 | { 545 | // No event specific data - the new weather mode is in the base structure dwData member. 546 | }; 547 | 548 | // SIMCONNECT_RECV_FACILITIES_LIST 549 | SIMCONNECT_REFSTRUCT SIMCONNECT_RECV_FACILITIES_LIST : public SIMCONNECT_RECV 550 | { 551 | DWORD dwRequestID; 552 | DWORD dwArraySize; 553 | DWORD dwEntryNumber; // when the array of items is too big for one send, which send this is (0..dwOutOf-1) 554 | DWORD dwOutOf; // total number of transmissions the list is chopped into 555 | }; 556 | 557 | // SIMCONNECT_DATA_FACILITY_AIRPORT 558 | SIMCONNECT_REFSTRUCT SIMCONNECT_DATA_FACILITY_AIRPORT 559 | { 560 | SIMCONNECT_STRING(Icao, 9); // ICAO of the object 561 | double Latitude; // degrees 562 | double Longitude; // degrees 563 | double Altitude; // meters 564 | }; 565 | 566 | // SIMCONNECT_RECV_AIRPORT_LIST 567 | SIMCONNECT_REFSTRUCT SIMCONNECT_RECV_AIRPORT_LIST : public SIMCONNECT_RECV_FACILITIES_LIST 568 | { 569 | SIMCONNECT_FIXEDTYPE_DATAV(SIMCONNECT_DATA_FACILITY_AIRPORT, rgData, dwArraySize, U1 /*member of UnmanagedType enum*/, SIMCONNECT_DATA_FACILITY_AIRPORT /*cli type*/); 570 | }; 571 | 572 | 573 | // SIMCONNECT_DATA_FACILITY_WAYPOINT 574 | SIMCONNECT_REFSTRUCT SIMCONNECT_DATA_FACILITY_WAYPOINT : public SIMCONNECT_DATA_FACILITY_AIRPORT 575 | { 576 | float fMagVar; // Magvar in degrees 577 | }; 578 | 579 | // SIMCONNECT_RECV_WAYPOINT_LIST 580 | SIMCONNECT_REFSTRUCT SIMCONNECT_RECV_WAYPOINT_LIST : public SIMCONNECT_RECV_FACILITIES_LIST 581 | { 582 | SIMCONNECT_FIXEDTYPE_DATAV(SIMCONNECT_DATA_FACILITY_WAYPOINT, rgData, dwArraySize, U1 /*member of UnmanagedType enum*/, SIMCONNECT_DATA_FACILITY_WAYPOINT /*cli type*/); 583 | }; 584 | 585 | // SIMCONNECT_DATA_FACILITY_NDB 586 | SIMCONNECT_REFSTRUCT SIMCONNECT_DATA_FACILITY_NDB : public SIMCONNECT_DATA_FACILITY_WAYPOINT 587 | { 588 | DWORD fFrequency; // frequency in Hz 589 | }; 590 | 591 | // SIMCONNECT_RECV_NDB_LIST 592 | SIMCONNECT_REFSTRUCT SIMCONNECT_RECV_NDB_LIST : public SIMCONNECT_RECV_FACILITIES_LIST 593 | { 594 | SIMCONNECT_FIXEDTYPE_DATAV(SIMCONNECT_DATA_FACILITY_NDB, rgData, dwArraySize, U1 /*member of UnmanagedType enum*/, SIMCONNECT_DATA_FACILITY_NDB /*cli type*/); 595 | }; 596 | 597 | // SIMCONNECT_DATA_FACILITY_VOR 598 | SIMCONNECT_REFSTRUCT SIMCONNECT_DATA_FACILITY_VOR : public SIMCONNECT_DATA_FACILITY_NDB 599 | { 600 | DWORD Flags; // SIMCONNECT_VOR_FLAGS 601 | float fLocalizer; // Localizer in degrees 602 | double GlideLat; // Glide Slope Location (deg, deg, meters) 603 | double GlideLon; 604 | double GlideAlt; 605 | float fGlideSlopeAngle; // Glide Slope in degrees 606 | }; 607 | 608 | // SIMCONNECT_RECV_VOR_LIST 609 | SIMCONNECT_REFSTRUCT SIMCONNECT_RECV_VOR_LIST : public SIMCONNECT_RECV_FACILITIES_LIST 610 | { 611 | SIMCONNECT_FIXEDTYPE_DATAV(SIMCONNECT_DATA_FACILITY_VOR, rgData, dwArraySize, U1 /*member of UnmanagedType enum*/, SIMCONNECT_DATA_FACILITY_VOR /*cli type*/); 612 | }; 613 | 614 | #ifdef ENABLE_SIMCONNECT_EXPERIMENTAL 615 | 616 | SIMCONNECT_REFSTRUCT SIMCONNECT_RECV_PICK : public SIMCONNECT_RECV // when dwID == SIMCONNECT_RECV_ID_RESERVED_KEY 617 | { 618 | HANDLE hContext; 619 | DWORD dwFlags; // 620 | double Latitude; // degrees 621 | double Longitude; // degrees 622 | double Altitude; // feet 623 | int xPos; //reserved 624 | int yPos; //reserved; 625 | DWORD dwSimObjectID; 626 | HANDLE hSceneryObject; 627 | DWORD dwentrynumber; // if multiple objects returned, this is number out of . 628 | DWORD dwoutof; // note: starts with 1, not 0. 629 | }; 630 | 631 | #endif //ENABLE_SIMCONNECT_EXPERIMENTAL 632 | 633 | 634 | // SIMCONNECT_DATATYPE_INITPOSITION 635 | SIMCONNECT_STRUCT SIMCONNECT_DATA_INITPOSITION 636 | { 637 | double Latitude; // degrees 638 | double Longitude; // degrees 639 | double Altitude; // feet 640 | double Pitch; // degrees 641 | double Bank; // degrees 642 | double Heading; // degrees 643 | DWORD OnGround; // 1=force to be on the ground 644 | DWORD Airspeed; // knots 645 | }; 646 | 647 | 648 | // SIMCONNECT_DATATYPE_MARKERSTATE 649 | SIMCONNECT_STRUCT SIMCONNECT_DATA_MARKERSTATE 650 | { 651 | SIMCONNECT_STRING( szMarkerName, 64); 652 | DWORD dwMarkerState; 653 | }; 654 | 655 | // SIMCONNECT_DATATYPE_WAYPOINT 656 | SIMCONNECT_STRUCT SIMCONNECT_DATA_WAYPOINT 657 | { 658 | double Latitude; // degrees 659 | double Longitude; // degrees 660 | double Altitude; // feet 661 | unsigned long Flags; 662 | double ktsSpeed; // knots 663 | double percentThrottle; 664 | }; 665 | 666 | // SIMCONNECT_DATA_LATLONALT 667 | SIMCONNECT_STRUCT SIMCONNECT_DATA_LATLONALT 668 | { 669 | double Latitude; 670 | double Longitude; 671 | double Altitude; 672 | }; 673 | 674 | // SIMCONNECT_DATA_XYZ 675 | SIMCONNECT_STRUCT SIMCONNECT_DATA_XYZ 676 | { 677 | double x; 678 | double y; 679 | double z; 680 | }; 681 | 682 | #pragma pack(pop) 683 | 684 | //---------------------------------------------------------------------------- 685 | // End of Struct definitions 686 | //---------------------------------------------------------------------------- 687 | 688 | typedef void (CALLBACK *DispatchProc)(SIMCONNECT_RECV* pData, DWORD cbData, void* pContext); 689 | 690 | #if !defined(SIMCONNECTAPI) 691 | #ifdef _MSFS_WASM 692 | #ifdef __INTELLISENSE__ 693 | #define MODULE_EXPORT 694 | #define SIMCONNECTAPI extern "C" HRESULT 695 | #else 696 | #define MODULE_EXPORT __attribute__( ( visibility( "default" ) ) ) 697 | #define SIMCONNECTAPI extern "C" __attribute__((import_module(SIMCONNECT_WASM_MODULE))) HRESULT 698 | #endif 699 | #else 700 | #define MODULE_EXPORT 701 | #define SIMCONNECTAPI extern "C" HRESULT __stdcall 702 | #endif 703 | #endif 704 | 705 | SIMCONNECTAPI SimConnect_MapClientEventToSimEvent(HANDLE hSimConnect, SIMCONNECT_CLIENT_EVENT_ID EventID, const char * EventName = ""); 706 | SIMCONNECTAPI SimConnect_TransmitClientEvent(HANDLE hSimConnect, SIMCONNECT_OBJECT_ID ObjectID, SIMCONNECT_CLIENT_EVENT_ID EventID, DWORD dwData, SIMCONNECT_NOTIFICATION_GROUP_ID GroupID, SIMCONNECT_EVENT_FLAG Flags); 707 | SIMCONNECTAPI SimConnect_SetSystemEventState(HANDLE hSimConnect, SIMCONNECT_CLIENT_EVENT_ID EventID, SIMCONNECT_STATE dwState); 708 | SIMCONNECTAPI SimConnect_AddClientEventToNotificationGroup(HANDLE hSimConnect, SIMCONNECT_NOTIFICATION_GROUP_ID GroupID, SIMCONNECT_CLIENT_EVENT_ID EventID, BOOL bMaskable = FALSE); 709 | SIMCONNECTAPI SimConnect_RemoveClientEvent(HANDLE hSimConnect, SIMCONNECT_NOTIFICATION_GROUP_ID GroupID, SIMCONNECT_CLIENT_EVENT_ID EventID); 710 | SIMCONNECTAPI SimConnect_SetNotificationGroupPriority(HANDLE hSimConnect, SIMCONNECT_NOTIFICATION_GROUP_ID GroupID, DWORD uPriority); 711 | SIMCONNECTAPI SimConnect_ClearNotificationGroup(HANDLE hSimConnect, SIMCONNECT_NOTIFICATION_GROUP_ID GroupID); 712 | SIMCONNECTAPI SimConnect_RequestNotificationGroup(HANDLE hSimConnect, SIMCONNECT_NOTIFICATION_GROUP_ID GroupID, DWORD dwReserved = 0, DWORD Flags = 0); 713 | SIMCONNECTAPI SimConnect_AddToDataDefinition(HANDLE hSimConnect, SIMCONNECT_DATA_DEFINITION_ID DefineID, const char * DatumName, const char * UnitsName, SIMCONNECT_DATATYPE DatumType = SIMCONNECT_DATATYPE_FLOAT64, float fEpsilon = 0, DWORD DatumID = SIMCONNECT_UNUSED); 714 | SIMCONNECTAPI SimConnect_ClearDataDefinition(HANDLE hSimConnect, SIMCONNECT_DATA_DEFINITION_ID DefineID); 715 | SIMCONNECTAPI SimConnect_RequestDataOnSimObject(HANDLE hSimConnect, SIMCONNECT_DATA_REQUEST_ID RequestID, SIMCONNECT_DATA_DEFINITION_ID DefineID, SIMCONNECT_OBJECT_ID ObjectID, SIMCONNECT_PERIOD Period, SIMCONNECT_DATA_REQUEST_FLAG Flags = 0, DWORD origin = 0, DWORD interval = 0, DWORD limit = 0); 716 | SIMCONNECTAPI SimConnect_RequestDataOnSimObjectType(HANDLE hSimConnect, SIMCONNECT_DATA_REQUEST_ID RequestID, SIMCONNECT_DATA_DEFINITION_ID DefineID, DWORD dwRadiusMeters, SIMCONNECT_SIMOBJECT_TYPE type); 717 | SIMCONNECTAPI SimConnect_SetDataOnSimObject(HANDLE hSimConnect, SIMCONNECT_DATA_DEFINITION_ID DefineID, SIMCONNECT_OBJECT_ID ObjectID, SIMCONNECT_DATA_SET_FLAG Flags, DWORD ArrayCount, DWORD cbUnitSize, void * pDataSet); 718 | SIMCONNECTAPI SimConnect_MapInputEventToClientEvent(HANDLE hSimConnect, SIMCONNECT_INPUT_GROUP_ID GroupID, const char * szInputDefinition, SIMCONNECT_CLIENT_EVENT_ID DownEventID, DWORD DownValue = 0, SIMCONNECT_CLIENT_EVENT_ID UpEventID = (SIMCONNECT_CLIENT_EVENT_ID)SIMCONNECT_UNUSED, DWORD UpValue = 0, BOOL bMaskable = FALSE); 719 | SIMCONNECTAPI SimConnect_SetInputGroupPriority(HANDLE hSimConnect, SIMCONNECT_INPUT_GROUP_ID GroupID, DWORD uPriority); 720 | SIMCONNECTAPI SimConnect_RemoveInputEvent(HANDLE hSimConnect, SIMCONNECT_INPUT_GROUP_ID GroupID, const char * szInputDefinition); 721 | SIMCONNECTAPI SimConnect_ClearInputGroup(HANDLE hSimConnect, SIMCONNECT_INPUT_GROUP_ID GroupID); 722 | SIMCONNECTAPI SimConnect_SetInputGroupState(HANDLE hSimConnect, SIMCONNECT_INPUT_GROUP_ID GroupID, DWORD dwState); 723 | SIMCONNECTAPI SimConnect_RequestReservedKey(HANDLE hSimConnect, SIMCONNECT_CLIENT_EVENT_ID EventID, const char * szKeyChoice1 = "", const char * szKeyChoice2 = "", const char * szKeyChoice3 = ""); 724 | SIMCONNECTAPI SimConnect_SubscribeToSystemEvent(HANDLE hSimConnect, SIMCONNECT_CLIENT_EVENT_ID EventID, const char * SystemEventName); 725 | SIMCONNECTAPI SimConnect_UnsubscribeFromSystemEvent(HANDLE hSimConnect, SIMCONNECT_CLIENT_EVENT_ID EventID); 726 | SIMCONNECTAPI SimConnect_WeatherRequestInterpolatedObservation(HANDLE hSimConnect, SIMCONNECT_DATA_REQUEST_ID RequestID, float lat, float lon, float alt); 727 | SIMCONNECTAPI SimConnect_WeatherRequestObservationAtStation(HANDLE hSimConnect, SIMCONNECT_DATA_REQUEST_ID RequestID, const char * szICAO); 728 | SIMCONNECTAPI SimConnect_WeatherRequestObservationAtNearestStation(HANDLE hSimConnect, SIMCONNECT_DATA_REQUEST_ID RequestID, float lat, float lon); 729 | SIMCONNECTAPI SimConnect_WeatherCreateStation(HANDLE hSimConnect, SIMCONNECT_DATA_REQUEST_ID RequestID, const char * szICAO, const char * szName, float lat, float lon, float alt); 730 | SIMCONNECTAPI SimConnect_WeatherRemoveStation(HANDLE hSimConnect, SIMCONNECT_DATA_REQUEST_ID RequestID, const char * szICAO); 731 | SIMCONNECTAPI SimConnect_WeatherSetObservation(HANDLE hSimConnect, DWORD Seconds, const char * szMETAR); 732 | SIMCONNECTAPI SimConnect_WeatherSetModeServer(HANDLE hSimConnect, DWORD dwPort, DWORD dwSeconds); 733 | SIMCONNECTAPI SimConnect_WeatherSetModeTheme(HANDLE hSimConnect, const char * szThemeName); 734 | SIMCONNECTAPI SimConnect_WeatherSetModeGlobal(HANDLE hSimConnect); 735 | SIMCONNECTAPI SimConnect_WeatherSetModeCustom(HANDLE hSimConnect); 736 | SIMCONNECTAPI SimConnect_WeatherSetDynamicUpdateRate(HANDLE hSimConnect, DWORD dwRate); 737 | SIMCONNECTAPI SimConnect_WeatherRequestCloudState(HANDLE hSimConnect, SIMCONNECT_DATA_REQUEST_ID RequestID, float minLat, float minLon, float minAlt, float maxLat, float maxLon, float maxAlt, DWORD dwFlags = 0); 738 | SIMCONNECTAPI SimConnect_WeatherCreateThermal(HANDLE hSimConnect, SIMCONNECT_DATA_REQUEST_ID RequestID, float lat, float lon, float alt, float radius, float height, float coreRate = 3.0f, float coreTurbulence = 0.05f, float sinkRate = 3.0f, float sinkTurbulence = 0.2f, float coreSize = 0.4f, float coreTransitionSize = 0.1f, float sinkLayerSize = 0.4f, float sinkTransitionSize = 0.1f); 739 | SIMCONNECTAPI SimConnect_WeatherRemoveThermal(HANDLE hSimConnect, SIMCONNECT_OBJECT_ID ObjectID); 740 | SIMCONNECTAPI SimConnect_AICreateParkedATCAircraft(HANDLE hSimConnect, const char * szContainerTitle, const char * szTailNumber, const char * szAirportID, SIMCONNECT_DATA_REQUEST_ID RequestID); 741 | SIMCONNECTAPI SimConnect_AICreateEnrouteATCAircraft(HANDLE hSimConnect, const char * szContainerTitle, const char * szTailNumber, int iFlightNumber, const char * szFlightPlanPath, double dFlightPlanPosition, BOOL bTouchAndGo, SIMCONNECT_DATA_REQUEST_ID RequestID); 742 | SIMCONNECTAPI SimConnect_AICreateNonATCAircraft(HANDLE hSimConnect, const char * szContainerTitle, const char * szTailNumber, SIMCONNECT_DATA_INITPOSITION InitPos, SIMCONNECT_DATA_REQUEST_ID RequestID); 743 | SIMCONNECTAPI SimConnect_AICreateSimulatedObject(HANDLE hSimConnect, const char * szContainerTitle, SIMCONNECT_DATA_INITPOSITION InitPos, SIMCONNECT_DATA_REQUEST_ID RequestID); 744 | SIMCONNECTAPI SimConnect_AIReleaseControl(HANDLE hSimConnect, SIMCONNECT_OBJECT_ID ObjectID, SIMCONNECT_DATA_REQUEST_ID RequestID); 745 | SIMCONNECTAPI SimConnect_AIRemoveObject(HANDLE hSimConnect, SIMCONNECT_OBJECT_ID ObjectID, SIMCONNECT_DATA_REQUEST_ID RequestID); 746 | SIMCONNECTAPI SimConnect_AISetAircraftFlightPlan(HANDLE hSimConnect, SIMCONNECT_OBJECT_ID ObjectID, const char * szFlightPlanPath, SIMCONNECT_DATA_REQUEST_ID RequestID); 747 | SIMCONNECTAPI SimConnect_ExecuteMissionAction(HANDLE hSimConnect, const GUID guidInstanceId); 748 | SIMCONNECTAPI SimConnect_CompleteCustomMissionAction(HANDLE hSimConnect, const GUID guidInstanceId); 749 | SIMCONNECTAPI SimConnect_Close(HANDLE hSimConnect); 750 | SIMCONNECTAPI SimConnect_RetrieveString(SIMCONNECT_RECV * pData, DWORD cbData, void * pStringV, char ** pszString, DWORD * pcbString); 751 | SIMCONNECTAPI SimConnect_GetLastSentPacketID(HANDLE hSimConnect, DWORD * pdwError); 752 | SIMCONNECTAPI SimConnect_Open(HANDLE * phSimConnect, LPCSTR szName, HWND hWnd, DWORD UserEventWin32, HANDLE hEventHandle, DWORD ConfigIndex); 753 | SIMCONNECTAPI SimConnect_CallDispatch(HANDLE hSimConnect, DispatchProc pfcnDispatch, void * pContext); 754 | SIMCONNECTAPI SimConnect_GetNextDispatch(HANDLE hSimConnect, SIMCONNECT_RECV ** ppData, DWORD * pcbData); 755 | SIMCONNECTAPI SimConnect_RequestResponseTimes(HANDLE hSimConnect, DWORD nCount, float * fElapsedSeconds); 756 | SIMCONNECTAPI SimConnect_InsertString(char * pDest, DWORD cbDest, void ** ppEnd, DWORD * pcbStringV, const char * pSource); 757 | SIMCONNECTAPI SimConnect_CameraSetRelative6DOF(HANDLE hSimConnect, float fDeltaX, float fDeltaY, float fDeltaZ, float fPitchDeg, float fBankDeg, float fHeadingDeg); 758 | SIMCONNECTAPI SimConnect_MenuAddItem(HANDLE hSimConnect, const char * szMenuItem, SIMCONNECT_CLIENT_EVENT_ID MenuEventID, DWORD dwData); 759 | SIMCONNECTAPI SimConnect_MenuDeleteItem(HANDLE hSimConnect, SIMCONNECT_CLIENT_EVENT_ID MenuEventID); 760 | SIMCONNECTAPI SimConnect_MenuAddSubItem(HANDLE hSimConnect, SIMCONNECT_CLIENT_EVENT_ID MenuEventID, const char * szMenuItem, SIMCONNECT_CLIENT_EVENT_ID SubMenuEventID, DWORD dwData); 761 | SIMCONNECTAPI SimConnect_MenuDeleteSubItem(HANDLE hSimConnect, SIMCONNECT_CLIENT_EVENT_ID MenuEventID, const SIMCONNECT_CLIENT_EVENT_ID SubMenuEventID); 762 | SIMCONNECTAPI SimConnect_RequestSystemState(HANDLE hSimConnect, SIMCONNECT_DATA_REQUEST_ID RequestID, const char * szState); 763 | SIMCONNECTAPI SimConnect_SetSystemState(HANDLE hSimConnect, const char * szState, DWORD dwInteger, float fFloat, const char * szString); 764 | SIMCONNECTAPI SimConnect_MapClientDataNameToID(HANDLE hSimConnect, const char * szClientDataName, SIMCONNECT_CLIENT_DATA_ID ClientDataID); 765 | SIMCONNECTAPI SimConnect_CreateClientData(HANDLE hSimConnect, SIMCONNECT_CLIENT_DATA_ID ClientDataID, DWORD dwSize, SIMCONNECT_CREATE_CLIENT_DATA_FLAG Flags); 766 | SIMCONNECTAPI SimConnect_AddToClientDataDefinition(HANDLE hSimConnect, SIMCONNECT_CLIENT_DATA_DEFINITION_ID DefineID, DWORD dwOffset, DWORD dwSizeOrType, float fEpsilon = 0, DWORD DatumID = SIMCONNECT_UNUSED); 767 | SIMCONNECTAPI SimConnect_ClearClientDataDefinition(HANDLE hSimConnect, SIMCONNECT_CLIENT_DATA_DEFINITION_ID DefineID); 768 | SIMCONNECTAPI SimConnect_RequestClientData(HANDLE hSimConnect, SIMCONNECT_CLIENT_DATA_ID ClientDataID, SIMCONNECT_DATA_REQUEST_ID RequestID, SIMCONNECT_CLIENT_DATA_DEFINITION_ID DefineID, SIMCONNECT_CLIENT_DATA_PERIOD Period = SIMCONNECT_CLIENT_DATA_PERIOD_ONCE, SIMCONNECT_CLIENT_DATA_REQUEST_FLAG Flags = 0, DWORD origin = 0, DWORD interval = 0, DWORD limit = 0); 769 | SIMCONNECTAPI SimConnect_SetClientData(HANDLE hSimConnect, SIMCONNECT_CLIENT_DATA_ID ClientDataID, SIMCONNECT_CLIENT_DATA_DEFINITION_ID DefineID, SIMCONNECT_CLIENT_DATA_SET_FLAG Flags, DWORD dwReserved, DWORD cbUnitSize, void * pDataSet); 770 | SIMCONNECTAPI SimConnect_FlightLoad(HANDLE hSimConnect, const char * szFileName); 771 | SIMCONNECTAPI SimConnect_FlightSave(HANDLE hSimConnect, const char * szFileName, const char * szTitle, const char * szDescription, DWORD Flags); 772 | SIMCONNECTAPI SimConnect_FlightPlanLoad(HANDLE hSimConnect, const char * szFileName); 773 | SIMCONNECTAPI SimConnect_Text(HANDLE hSimConnect, SIMCONNECT_TEXT_TYPE type, float fTimeSeconds, SIMCONNECT_CLIENT_EVENT_ID EventID, DWORD cbUnitSize, void * pDataSet); 774 | SIMCONNECTAPI SimConnect_SubscribeToFacilities(HANDLE hSimConnect, SIMCONNECT_FACILITY_LIST_TYPE type, SIMCONNECT_DATA_REQUEST_ID RequestID); 775 | SIMCONNECTAPI SimConnect_UnsubscribeToFacilities(HANDLE hSimConnect, SIMCONNECT_FACILITY_LIST_TYPE type); 776 | SIMCONNECTAPI SimConnect_RequestFacilitiesList(HANDLE hSimConnect, SIMCONNECT_FACILITY_LIST_TYPE type, SIMCONNECT_DATA_REQUEST_ID RequestID); 777 | 778 | #endif // _SIMCONNECT_H_ 779 | -------------------------------------------------------------------------------- /libsrc/lib/SimConnect.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sequal32/simconnect-rust/0fa414cd3859187c605edb388d5047675b1f8778/libsrc/lib/SimConnect.lib -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | #![allow(clippy::too_many_arguments, clippy::missing_safety_doc)] 2 | /*! 3 | The simconnect crate provides rust bindings to retrieve and send information through SimConnect. 4 | 5 | Documentation for SimConnect can be found by downloading the SDK for FS2020 or using P3D/FSX SDK documentations for reference (although some of their documentation does not apply for FS2020). 6 | 7 | # Setup 8 | Add this to your `Cargo.toml` 9 | ```toml 10 | [dependencies] 11 | simconnect = "0.1" 12 | ``` 13 | 14 | # Simple Example 15 | *Note: You must have SimConnect.dll in your current working directory to be able to successfully use SimConnect* 16 | ```rust 17 | use simconnect; 18 | use std::time::Duration; 19 | use std::thread::sleep; 20 | use std::mem::transmute_copy; 21 | 22 | struct DataStruct { 23 | lat: f64, 24 | lon: f64, 25 | alt: f64, 26 | } 27 | 28 | let mut conn = simconnect::SimConnector::new(); 29 | conn.connect("Simple Program"); // Intialize connection with SimConnect 30 | conn.add_data_definition(0, "PLANE LATITUDE", "Degrees", simconnect::SIMCONNECT_DATATYPE_SIMCONNECT_DATATYPE_FLOAT64, u32::MAX, 0.0); // Assign a sim variable to a client defined id 31 | conn.add_data_definition(0, "PLANE LONGITUDE", "Degrees", simconnect::SIMCONNECT_DATATYPE_SIMCONNECT_DATATYPE_FLOAT64, u32::MAX, 0.0); 32 | conn.add_data_definition(0, "PLANE ALTITUDE", "Feet", simconnect::SIMCONNECT_DATATYPE_SIMCONNECT_DATATYPE_FLOAT64, u32::MAX, 0.0); //define_id, units, data_type, datum_id, epsilon (per X change in sim variable, send data) 33 | conn.request_data_on_sim_object(0, 0, 0, simconnect::SIMCONNECT_PERIOD_SIMCONNECT_PERIOD_SIM_FRAME, 0, 0, 0, 0); //request_id, define_id, object_id (user), period, falgs, origin, interval, limit - tells simconnect to send data for the defined id and on the user aircraft 34 | 35 | loop { 36 | match conn.get_next_message() { 37 | Ok(simconnect::DispatchResult::SimobjectData(data)) => { 38 | unsafe { 39 | match data.dwDefineID { 40 | 0 => { 41 | let sim_data = std::ptr::addr_of!(data.dwData); 42 | let sim_data_ptr = sim_data as *const DataStruct; 43 | let sim_data_value = std::ptr::read_unaligned(sim_data_ptr); 44 | println!("{:?} {:?} {:?}", sim_data_value.lat, sim_data_value.lon, sim_data_value.alt); 45 | }, 46 | _ => () 47 | } 48 | } 49 | }, 50 | _ => () 51 | } 52 | 53 | sleep(Duration::from_millis(16)); // Will use up lots of CPU if this is not included, as get_next_message() is non-blocking 54 | } 55 | ``` 56 | !*/ 57 | 58 | #![allow(non_upper_case_globals)] 59 | #![allow(non_camel_case_types)] 60 | #![allow(non_snake_case)] 61 | 62 | use std::ffi::CString; 63 | use std::mem::transmute_copy; 64 | use std::ptr; 65 | 66 | include!(concat!(env!("OUT_DIR"), "/bindings.rs")); 67 | 68 | /// Enumerations for all the possible data types received from SimConnect 69 | #[derive(Debug)] 70 | pub enum DispatchResult<'a> { 71 | Null, 72 | Exception(&'a SIMCONNECT_RECV_EXCEPTION), 73 | Open(&'a SIMCONNECT_RECV_OPEN), 74 | Quit(&'a SIMCONNECT_RECV_QUIT), 75 | Event(&'a SIMCONNECT_RECV_EVENT), 76 | EventObjectAddRemove(&'a SIMCONNECT_RECV_EVENT_OBJECT_ADDREMOVE), 77 | EventFilename(&'a SIMCONNECT_RECV_EVENT_FILENAME), 78 | EventFrame(&'a SIMCONNECT_RECV_EVENT_FRAME), 79 | SimObjectData(&'a SIMCONNECT_RECV_SIMOBJECT_DATA), 80 | SimObjectDataByType(&'a SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE), 81 | WeatherObservation(&'a SIMCONNECT_RECV_WEATHER_OBSERVATION), 82 | CloudState(&'a SIMCONNECT_RECV_CLOUD_STATE), 83 | AssignedObjectId(&'a SIMCONNECT_RECV_ASSIGNED_OBJECT_ID), 84 | ReservedKey(&'a SIMCONNECT_RECV_RESERVED_KEY), 85 | CustomAction(&'a SIMCONNECT_RECV_CUSTOM_ACTION), 86 | SystemState(&'a SIMCONNECT_RECV_SYSTEM_STATE), 87 | ClientData(&'a SIMCONNECT_RECV_CLIENT_DATA), 88 | EventWeatherMode(&'a SIMCONNECT_RECV_EVENT_WEATHER_MODE), 89 | AirportList(&'a SIMCONNECT_RECV_AIRPORT_LIST), 90 | VorList(&'a SIMCONNECT_RECV_VOR_LIST), 91 | NdbList(&'a SIMCONNECT_RECV_NDB_LIST), 92 | WaypointList(&'a SIMCONNECT_RECV_WAYPOINT_LIST), 93 | EventMultiplayerServerStarted(&'a SIMCONNECT_RECV_EVENT_MULTIPLAYER_SERVER_STARTED), 94 | EventMultiplayerClientStarted(&'a SIMCONNECT_RECV_EVENT_MULTIPLAYER_CLIENT_STARTED), 95 | EventMultiplayerSessionEnded(&'a SIMCONNECT_RECV_EVENT_MULTIPLAYER_SESSION_ENDED), 96 | EventRaceEnd(&'a SIMCONNECT_RECV_EVENT_RACE_END), 97 | EventRaceLap(&'a SIMCONNECT_RECV_EVENT_RACE_LAP), 98 | } 99 | 100 | /// Handles communication between the client program and SimConnect 101 | /// For more information about the functions provided, refer to the SimConnect SDK Documentation. The functions name closely match up with those defined there. 102 | #[derive(Debug)] 103 | pub struct SimConnector { 104 | sim_connect_handle: HANDLE, 105 | } 106 | 107 | impl Default for SimConnector { 108 | fn default() -> Self { 109 | Self { 110 | sim_connect_handle: std::ptr::null_mut(), 111 | } 112 | } 113 | } 114 | 115 | impl SimConnector { 116 | pub fn new() -> Self { 117 | Self::default() 118 | } 119 | 120 | pub fn connect(&mut self, program_name: &str) -> bool { 121 | unsafe { 122 | let temp_1 = ptr::null_mut(); 123 | let temp_2 = ptr::null_mut(); 124 | 125 | let program_name = CString::new(program_name).unwrap(); 126 | 127 | SimConnect_Open( 128 | &mut self.sim_connect_handle, 129 | program_name.as_ptr(), 130 | temp_1, 131 | 0, 132 | temp_2, 133 | 0, 134 | ); 135 | 136 | !self.sim_connect_handle.is_null() 137 | } 138 | } 139 | 140 | pub fn add_data_definition( 141 | &self, 142 | define_id: SIMCONNECT_DATA_DEFINITION_ID, 143 | datum_name: &str, 144 | units_name: &str, 145 | datum_type: SIMCONNECT_DATATYPE, 146 | datum_id: DWORD, 147 | epsilon: f32, 148 | ) -> bool { 149 | let datum_name = CString::new(datum_name).unwrap(); 150 | let units_name = CString::new(units_name).unwrap(); 151 | 152 | unsafe { 153 | SimConnect_AddToDataDefinition( 154 | self.sim_connect_handle, 155 | define_id, 156 | datum_name.as_ptr(), 157 | units_name.as_ptr(), 158 | datum_type, 159 | epsilon, 160 | datum_id, 161 | ) == 0 162 | } 163 | } 164 | 165 | pub fn set_system_event_state( 166 | &self, 167 | event_id: SIMCONNECT_CLIENT_EVENT_ID, 168 | state: SIMCONNECT_STATE, 169 | ) -> bool { 170 | unsafe { SimConnect_SetSystemEventState(self.sim_connect_handle, event_id, state) == 0 } 171 | } 172 | 173 | pub fn remove_client_event( 174 | &self, 175 | group_id: SIMCONNECT_NOTIFICATION_GROUP_ID, 176 | event_id: SIMCONNECT_CLIENT_EVENT_ID, 177 | ) -> bool { 178 | unsafe { SimConnect_RemoveClientEvent(self.sim_connect_handle, group_id, event_id) == 0 } 179 | } 180 | 181 | pub fn clear_notification_group(&self, group_id: SIMCONNECT_NOTIFICATION_GROUP_ID) -> bool { 182 | unsafe { SimConnect_ClearNotificationGroup(self.sim_connect_handle, group_id) == 0 } 183 | } 184 | 185 | pub fn request_notification_group( 186 | &self, 187 | group_id: SIMCONNECT_NOTIFICATION_GROUP_ID, 188 | reserved: DWORD, 189 | flags: DWORD, 190 | ) -> bool { 191 | unsafe { 192 | SimConnect_RequestNotificationGroup(self.sim_connect_handle, group_id, reserved, flags) 193 | == 0 194 | } 195 | } 196 | 197 | pub fn clear_data_definition(&self, define_id: SIMCONNECT_DATA_DEFINITION_ID) -> bool { 198 | unsafe { SimConnect_ClearDataDefinition(self.sim_connect_handle, define_id) == 0 } 199 | } 200 | 201 | pub fn create_client_data( 202 | &self, 203 | data_id: SIMCONNECT_CLIENT_DATA_ID, 204 | size: DWORD, 205 | flags: SIMCONNECT_CREATE_CLIENT_DATA_FLAG, 206 | ) -> bool { 207 | unsafe { SimConnect_CreateClientData(self.sim_connect_handle, data_id, size, flags) == 0 } 208 | } 209 | 210 | pub fn request_data_on_sim_object_type( 211 | &self, 212 | request_id: SIMCONNECT_DATA_REQUEST_ID, 213 | define_id: SIMCONNECT_DATA_DEFINITION_ID, 214 | radius_in_meters: DWORD, 215 | object_type: SIMCONNECT_SIMOBJECT_TYPE, 216 | ) -> bool { 217 | unsafe { 218 | SimConnect_RequestDataOnSimObjectType( 219 | self.sim_connect_handle, 220 | request_id, 221 | define_id, 222 | radius_in_meters, 223 | object_type, 224 | ) == 0 225 | } 226 | } 227 | 228 | pub fn remove_input_event( 229 | &self, 230 | group_id: SIMCONNECT_INPUT_GROUP_ID, 231 | input_definition: &str, 232 | ) -> bool { 233 | let input_definition = CString::new(input_definition).unwrap(); 234 | 235 | unsafe { 236 | SimConnect_RemoveInputEvent( 237 | self.sim_connect_handle, 238 | group_id, 239 | input_definition.as_ptr(), 240 | ) == 0 241 | } 242 | } 243 | 244 | pub fn clear_input_group(&self, group_id: SIMCONNECT_INPUT_GROUP_ID) -> bool { 245 | unsafe { SimConnect_ClearInputGroup(self.sim_connect_handle, group_id) == 0 } 246 | } 247 | 248 | pub fn request_reserved_Key( 249 | &self, 250 | event_id: SIMCONNECT_CLIENT_EVENT_ID, 251 | key_choice_1: &str, 252 | key_choice_2: &str, 253 | key_choice_3: &str, 254 | ) -> bool { 255 | let key_choice_1 = CString::new(key_choice_1).unwrap(); 256 | let key_choice_2 = CString::new(key_choice_2).unwrap(); 257 | let key_choice_3 = CString::new(key_choice_3).unwrap(); 258 | 259 | unsafe { 260 | SimConnect_RequestReservedKey( 261 | self.sim_connect_handle, 262 | event_id, 263 | key_choice_1.as_ptr(), 264 | key_choice_2.as_ptr(), 265 | key_choice_3.as_ptr(), 266 | ) == 0 267 | } 268 | } 269 | 270 | pub fn unsubscribe_from_system_event(&self, event_id: SIMCONNECT_CLIENT_EVENT_ID) -> bool { 271 | unsafe { SimConnect_UnsubscribeFromSystemEvent(self.sim_connect_handle, event_id) == 0 } 272 | } 273 | 274 | pub fn ai_create_parked_atc_aircraft( 275 | &self, 276 | container_title: &str, 277 | tail_number: &str, 278 | airport_id: &str, 279 | request_id: SIMCONNECT_DATA_REQUEST_ID, 280 | ) -> bool { 281 | let container_title = CString::new(container_title).unwrap(); 282 | let tail_number = CString::new(tail_number).unwrap(); 283 | let airport_id = CString::new(airport_id).unwrap(); 284 | 285 | unsafe { 286 | SimConnect_AICreateParkedATCAircraft( 287 | self.sim_connect_handle, 288 | container_title.as_ptr(), 289 | tail_number.as_ptr(), 290 | airport_id.as_ptr(), 291 | request_id, 292 | ) == 0 293 | } 294 | } 295 | 296 | pub fn ai_create_enroute_atc_aircraft( 297 | &self, 298 | container_title: &str, 299 | tail_number: &str, 300 | flight_number: i32, 301 | flight_plan_path: &str, 302 | flight_plan_position: f64, 303 | touch_and_go: bool, 304 | request_id: SIMCONNECT_DATA_REQUEST_ID, 305 | ) -> bool { 306 | let container_title = CString::new(container_title).unwrap(); 307 | let tail_number = CString::new(tail_number).unwrap(); 308 | let flight_plan_path = CString::new(flight_plan_path).unwrap(); 309 | 310 | unsafe { 311 | SimConnect_AICreateEnrouteATCAircraft( 312 | self.sim_connect_handle, 313 | container_title.as_ptr(), 314 | tail_number.as_ptr(), 315 | flight_number, 316 | flight_plan_path.as_ptr(), 317 | flight_plan_position, 318 | touch_and_go as i32, 319 | request_id, 320 | ) == 0 321 | } 322 | } 323 | 324 | pub fn ai_create_non_atc_aircraft( 325 | &self, 326 | container_title: &str, 327 | tail_number: &str, 328 | init_pos: SIMCONNECT_DATA_INITPOSITION, 329 | request_id: SIMCONNECT_DATA_REQUEST_ID, 330 | ) -> bool { 331 | let container_title = CString::new(container_title).unwrap(); 332 | let tail_number = CString::new(tail_number).unwrap(); 333 | 334 | unsafe { 335 | SimConnect_AICreateNonATCAircraft( 336 | self.sim_connect_handle, 337 | container_title.as_ptr(), 338 | tail_number.as_ptr(), 339 | init_pos, 340 | request_id, 341 | ) == 0 342 | } 343 | } 344 | 345 | pub fn ai_create_simulated_object( 346 | &self, 347 | container_title: &str, 348 | init_pos: SIMCONNECT_DATA_INITPOSITION, 349 | request_id: SIMCONNECT_DATA_REQUEST_ID, 350 | ) -> bool { 351 | let container_title = CString::new(container_title).unwrap(); 352 | 353 | unsafe { 354 | SimConnect_AICreateSimulatedObject( 355 | self.sim_connect_handle, 356 | container_title.as_ptr(), 357 | init_pos, 358 | request_id, 359 | ) == 0 360 | } 361 | } 362 | 363 | pub fn ai_release_control( 364 | &self, 365 | object_id: SIMCONNECT_OBJECT_ID, 366 | request_id: SIMCONNECT_DATA_REQUEST_ID, 367 | ) -> bool { 368 | unsafe { SimConnect_AIReleaseControl(self.sim_connect_handle, object_id, request_id) == 0 } 369 | } 370 | 371 | pub fn ai_remove_object( 372 | &self, 373 | object_id: SIMCONNECT_OBJECT_ID, 374 | request_id: SIMCONNECT_DATA_REQUEST_ID, 375 | ) -> bool { 376 | unsafe { SimConnect_AIRemoveObject(self.sim_connect_handle, object_id, request_id) == 0 } 377 | } 378 | 379 | pub fn ai_set_aircraft_flight_plan( 380 | &self, 381 | object_id: SIMCONNECT_OBJECT_ID, 382 | flight_plan_path: &str, 383 | request_id: SIMCONNECT_DATA_REQUEST_ID, 384 | ) -> bool { 385 | let flight_plan_path = CString::new(flight_plan_path).unwrap(); 386 | 387 | unsafe { 388 | SimConnect_AISetAircraftFlightPlan( 389 | self.sim_connect_handle, 390 | object_id, 391 | flight_plan_path.as_ptr(), 392 | request_id, 393 | ) == 0 394 | } 395 | } 396 | 397 | pub fn execute_mission_action(&self, instance_id: GUID) -> bool { 398 | unsafe { SimConnect_ExecuteMissionAction(self.sim_connect_handle, instance_id) == 0 } 399 | } 400 | 401 | pub fn complete_custom_mission_action(&self, instance_id: GUID) -> bool { 402 | unsafe { SimConnect_CompleteCustomMissionAction(self.sim_connect_handle, instance_id) == 0 } 403 | } 404 | 405 | pub fn close(&self) -> bool { 406 | unsafe { SimConnect_Close(self.sim_connect_handle) == 0 } 407 | } 408 | 409 | pub unsafe fn get_last_sent_packet_id(&self, error: *mut DWORD) -> bool { 410 | unsafe { SimConnect_GetLastSentPacketID(self.sim_connect_handle, error) == 0 } 411 | } 412 | 413 | // not tested 414 | pub unsafe fn call_dispatch( 415 | &self, 416 | dispatch_callback: DispatchProc, 417 | context: *mut std::os::raw::c_void, 418 | ) -> bool { 419 | unsafe { SimConnect_CallDispatch(self.sim_connect_handle, dispatch_callback, context) == 0 } 420 | } 421 | 422 | pub unsafe fn request_response_times(&self, count: DWORD, elapsed_seconds: *mut f32) -> bool { 423 | unsafe { 424 | SimConnect_RequestResponseTimes(self.sim_connect_handle, count, elapsed_seconds) == 0 425 | } 426 | } 427 | 428 | pub fn camera_set_relative_6dof( 429 | &self, 430 | delta_x: f32, 431 | delta_y: f32, 432 | delta_z: f32, 433 | pitch: f32, 434 | bank: f32, 435 | heading: f32, 436 | ) -> bool { 437 | unsafe { 438 | SimConnect_CameraSetRelative6DOF( 439 | self.sim_connect_handle, 440 | delta_x, 441 | delta_y, 442 | delta_z, 443 | pitch, 444 | bank, 445 | heading, 446 | ) == 0 447 | } 448 | } 449 | 450 | pub fn menu_add_item( 451 | &self, 452 | menu_item: &str, 453 | event_id: SIMCONNECT_CLIENT_EVENT_ID, 454 | data: DWORD, 455 | ) -> bool { 456 | let menu_item = CString::new(menu_item).unwrap(); 457 | 458 | unsafe { 459 | SimConnect_MenuAddItem(self.sim_connect_handle, menu_item.as_ptr(), event_id, data) == 0 460 | } 461 | } 462 | 463 | pub fn menu_delete_item(&self, event_id: SIMCONNECT_CLIENT_EVENT_ID) -> bool { 464 | unsafe { SimConnect_MenuDeleteItem(self.sim_connect_handle, event_id) == 0 } 465 | } 466 | 467 | pub fn menu_delete_sub_item( 468 | &self, 469 | event_id: SIMCONNECT_CLIENT_EVENT_ID, 470 | sub_event_id: SIMCONNECT_CLIENT_EVENT_ID, 471 | ) -> bool { 472 | unsafe { 473 | SimConnect_MenuDeleteSubItem(self.sim_connect_handle, event_id, sub_event_id) == 0 474 | } 475 | } 476 | 477 | pub fn request_system_state( 478 | &self, 479 | request_id: SIMCONNECT_DATA_REQUEST_ID, 480 | state: &str, 481 | ) -> bool { 482 | let state = CString::new(state).unwrap(); 483 | 484 | unsafe { 485 | SimConnect_RequestSystemState(self.sim_connect_handle, request_id, state.as_ptr()) == 0 486 | } 487 | } 488 | 489 | pub fn map_client_data_name_to_id( 490 | &self, 491 | client_data_name: &str, 492 | data_id: SIMCONNECT_CLIENT_DATA_ID, 493 | ) -> bool { 494 | let client_data_name = CString::new(client_data_name).unwrap(); 495 | 496 | unsafe { 497 | SimConnect_MapClientDataNameToID( 498 | self.sim_connect_handle, 499 | client_data_name.as_ptr(), 500 | data_id, 501 | ) == 0 502 | } 503 | } 504 | 505 | pub fn add_to_client_data_definition( 506 | &self, 507 | define_id: SIMCONNECT_DATA_DEFINITION_ID, 508 | offset: DWORD, 509 | size_or_type: DWORD, 510 | epsilon: f32, 511 | datum_id: DWORD, 512 | ) -> bool { 513 | unsafe { 514 | SimConnect_AddToClientDataDefinition( 515 | self.sim_connect_handle, 516 | define_id, 517 | offset, 518 | size_or_type, 519 | epsilon, 520 | datum_id, 521 | ) == 0 522 | } 523 | } 524 | 525 | pub fn clear_client_data_definition(&self, define_id: SIMCONNECT_DATA_DEFINITION_ID) -> bool { 526 | unsafe { SimConnect_ClearClientDataDefinition(self.sim_connect_handle, define_id) == 0 } 527 | } 528 | 529 | pub fn request_client_data( 530 | &self, 531 | data_id: SIMCONNECT_CLIENT_DATA_ID, 532 | request_id: SIMCONNECT_DATA_REQUEST_ID, 533 | define_id: SIMCONNECT_DATA_DEFINITION_ID, 534 | period: SIMCONNECT_CLIENT_DATA_PERIOD, 535 | flags: SIMCONNECT_CLIENT_DATA_REQUEST_FLAG, 536 | origin: DWORD, 537 | interval: DWORD, 538 | limit: DWORD, 539 | ) -> bool { 540 | unsafe { 541 | SimConnect_RequestClientData( 542 | self.sim_connect_handle, 543 | data_id, 544 | request_id, 545 | define_id, 546 | period, 547 | flags, 548 | origin, 549 | interval, 550 | limit, 551 | ) == 0 552 | } 553 | } 554 | 555 | pub unsafe fn set_client_data( 556 | &self, 557 | data_id: SIMCONNECT_CLIENT_DATA_ID, 558 | define_id: SIMCONNECT_DATA_DEFINITION_ID, 559 | flags: DWORD, 560 | reserved: DWORD, 561 | unit_size: DWORD, 562 | data_set: *mut std::os::raw::c_void, 563 | ) -> bool { 564 | unsafe { 565 | SimConnect_SetClientData( 566 | self.sim_connect_handle, 567 | data_id, 568 | define_id, 569 | flags, 570 | reserved, 571 | unit_size, 572 | data_set, 573 | ) == 0 574 | } 575 | } 576 | 577 | pub fn flight_load(&self, file_name: &str) -> bool { 578 | let file_name = CString::new(file_name).unwrap(); 579 | 580 | unsafe { SimConnect_FlightLoad(self.sim_connect_handle, file_name.as_ptr()) == 0 } 581 | } 582 | 583 | pub unsafe fn text( 584 | &self, 585 | text_type: SIMCONNECT_TEXT_TYPE, 586 | time_in_seconds: f32, 587 | event_id: SIMCONNECT_CLIENT_EVENT_ID, 588 | unit_size: DWORD, 589 | data_set: *mut std::os::raw::c_void, 590 | ) -> bool { 591 | unsafe { 592 | SimConnect_Text( 593 | self.sim_connect_handle, 594 | text_type, 595 | time_in_seconds, 596 | event_id, 597 | unit_size, 598 | data_set, 599 | ) == 0 600 | } 601 | } 602 | 603 | pub unsafe fn subscribe_to_facilities( 604 | &self, 605 | list_type: SIMCONNECT_FACILITY_LIST_TYPE, 606 | request_id: SIMCONNECT_DATA_REQUEST_ID, 607 | ) -> bool { 608 | unsafe { 609 | SimConnect_SubscribeToFacilities(self.sim_connect_handle, list_type, request_id) == 0 610 | } 611 | } 612 | 613 | pub fn unsubscribe_to_facilities(&self, list_type: SIMCONNECT_FACILITY_LIST_TYPE) -> bool { 614 | unsafe { SimConnect_UnsubscribeToFacilities(self.sim_connect_handle, list_type) == 0 } 615 | } 616 | 617 | pub fn request_facilities_list( 618 | &self, 619 | list_type: SIMCONNECT_FACILITY_LIST_TYPE, 620 | request_id: SIMCONNECT_DATA_REQUEST_ID, 621 | ) -> bool { 622 | unsafe { 623 | SimConnect_RequestFacilitiesList(self.sim_connect_handle, list_type, request_id) == 0 624 | } 625 | } 626 | 627 | pub fn request_data_on_sim_object( 628 | &self, 629 | request_id: SIMCONNECT_DATA_REQUEST_ID, 630 | define_id: SIMCONNECT_DATA_DEFINITION_ID, 631 | object_id: SIMCONNECT_OBJECT_ID, 632 | period: SIMCONNECT_CLIENT_DATA_PERIOD, 633 | flags: SIMCONNECT_DATA_REQUEST_FLAG, 634 | origin: DWORD, 635 | interval: DWORD, 636 | limit: DWORD, 637 | ) -> bool { 638 | unsafe { 639 | SimConnect_RequestDataOnSimObject( 640 | self.sim_connect_handle, 641 | request_id, 642 | define_id, 643 | object_id, 644 | period, 645 | flags, 646 | origin, 647 | interval, 648 | limit, 649 | ) == 0 650 | } 651 | } 652 | 653 | pub unsafe fn set_data_on_sim_object( 654 | &self, 655 | define_id: SIMCONNECT_DATA_DEFINITION_ID, 656 | object_id: SIMCONNECT_OBJECT_ID, 657 | flags: SIMCONNECT_DATA_SET_FLAG, 658 | array_count: DWORD, 659 | size: DWORD, 660 | pntr: *mut ::std::os::raw::c_void, 661 | ) -> bool { 662 | unsafe { 663 | SimConnect_SetDataOnSimObject( 664 | self.sim_connect_handle, 665 | define_id, 666 | object_id, 667 | flags, 668 | array_count, 669 | size, 670 | pntr, 671 | ) == 0 672 | } 673 | } 674 | 675 | pub fn subscribe_to_system_event( 676 | &self, 677 | event_id: SIMCONNECT_CLIENT_EVENT_ID, 678 | event_name: &str, 679 | ) -> bool { 680 | let event_name = CString::new(event_name).unwrap(); 681 | 682 | unsafe { 683 | SimConnect_SubscribeToSystemEvent( 684 | self.sim_connect_handle, 685 | event_id, 686 | event_name.as_ptr(), 687 | ) == 0 688 | } 689 | } 690 | 691 | pub fn map_client_event_to_sim_event( 692 | &self, 693 | event_id: SIMCONNECT_CLIENT_EVENT_ID, 694 | event_name: &str, 695 | ) -> bool { 696 | let event_name = CString::new(event_name).unwrap(); 697 | 698 | unsafe { 699 | SimConnect_MapClientEventToSimEvent( 700 | self.sim_connect_handle, 701 | event_id, 702 | event_name.as_ptr(), 703 | ) == 0 704 | } 705 | } 706 | 707 | pub fn transmit_client_event( 708 | &self, 709 | object_id: SIMCONNECT_OBJECT_ID, 710 | event_id: SIMCONNECT_CLIENT_EVENT_ID, 711 | dw_data: DWORD, 712 | group_id: SIMCONNECT_NOTIFICATION_GROUP_ID, 713 | flags: SIMCONNECT_EVENT_FLAG, 714 | ) -> bool { 715 | unsafe { 716 | SimConnect_TransmitClientEvent( 717 | self.sim_connect_handle, 718 | object_id, 719 | event_id, 720 | dw_data, 721 | group_id, 722 | flags, 723 | ) == 0 724 | } 725 | } 726 | 727 | pub fn add_client_event_to_notification_group( 728 | &self, 729 | group_id: SIMCONNECT_NOTIFICATION_GROUP_ID, 730 | event_id: SIMCONNECT_CLIENT_EVENT_ID, 731 | maskable: bool, 732 | ) -> bool { 733 | unsafe { 734 | SimConnect_AddClientEventToNotificationGroup( 735 | self.sim_connect_handle, 736 | group_id, 737 | event_id, 738 | maskable as i32, 739 | ) == 0 740 | } 741 | } 742 | 743 | pub fn set_notification_group_priority( 744 | &self, 745 | group_id: SIMCONNECT_NOTIFICATION_GROUP_ID, 746 | priority: DWORD, 747 | ) -> bool { 748 | unsafe { 749 | SimConnect_SetNotificationGroupPriority(self.sim_connect_handle, group_id, priority) 750 | == 0 751 | } 752 | } 753 | 754 | pub fn map_input_event_to_client_event( 755 | &self, 756 | group_id: SIMCONNECT_INPUT_GROUP_ID, 757 | input_definition: &str, 758 | down_event: SIMCONNECT_CLIENT_EVENT_ID, 759 | down_return_value: DWORD, 760 | up_event: SIMCONNECT_CLIENT_EVENT_ID, 761 | up_return_value: DWORD, 762 | maskable: bool, 763 | ) -> bool { 764 | let input_definition = CString::new(input_definition).unwrap(); 765 | 766 | unsafe { 767 | SimConnect_MapInputEventToClientEvent( 768 | self.sim_connect_handle, 769 | group_id, 770 | input_definition.as_ptr(), 771 | down_event, 772 | down_return_value, 773 | up_event, 774 | up_return_value, 775 | maskable as i32, 776 | ) == 0 777 | } 778 | } 779 | 780 | pub fn set_input_group_state(&self, group_id: SIMCONNECT_INPUT_GROUP_ID, state: DWORD) -> bool { 781 | unsafe { SimConnect_SetInputGroupState(self.sim_connect_handle, group_id, state) == 0 } 782 | } 783 | 784 | pub fn set_input_priority(&self, group_id: SIMCONNECT_INPUT_GROUP_ID, priority: DWORD) -> bool { 785 | unsafe { 786 | SimConnect_SetInputGroupPriority(self.sim_connect_handle, group_id, priority) == 0 787 | } 788 | } 789 | 790 | /// Retrieves the next message from SimConnect. Nonblocking. 791 | pub fn get_next_message(&self) -> Result { 792 | let mut data_buf: *mut SIMCONNECT_RECV = ptr::null_mut(); 793 | 794 | let mut size_buf: DWORD = 32; 795 | let size_buf_pointer: *mut DWORD = &mut size_buf; 796 | 797 | unsafe { 798 | let result = SimConnect_GetNextDispatch( 799 | self.sim_connect_handle, 800 | &mut data_buf, 801 | size_buf_pointer, 802 | ); 803 | if result != 0 { 804 | return Err("Failed getting data!"); 805 | } 806 | 807 | return match (*data_buf).dwID as SIMCONNECT_RECV_ID { 808 | SIMCONNECT_RECV_ID_SIMCONNECT_RECV_ID_NULL => Ok(DispatchResult::Null), 809 | SIMCONNECT_RECV_ID_SIMCONNECT_RECV_ID_EXCEPTION => Ok(DispatchResult::Exception( 810 | transmute_copy(&(data_buf as *const SIMCONNECT_RECV_EXCEPTION)), 811 | )), 812 | SIMCONNECT_RECV_ID_SIMCONNECT_RECV_ID_OPEN => Ok(DispatchResult::Open( 813 | transmute_copy(&(data_buf as *const SIMCONNECT_RECV_OPEN)), 814 | )), 815 | SIMCONNECT_RECV_ID_SIMCONNECT_RECV_ID_QUIT => Ok(DispatchResult::Quit( 816 | transmute_copy(&(data_buf as *const SIMCONNECT_RECV_QUIT)), 817 | )), 818 | SIMCONNECT_RECV_ID_SIMCONNECT_RECV_ID_EVENT => Ok(DispatchResult::Event( 819 | transmute_copy(&(data_buf as *const SIMCONNECT_RECV_EVENT)), 820 | )), 821 | SIMCONNECT_RECV_ID_SIMCONNECT_RECV_ID_EVENT_OBJECT_ADDREMOVE => { 822 | Ok(DispatchResult::EventObjectAddRemove(transmute_copy( 823 | &(data_buf as *const SIMCONNECT_RECV_EVENT_OBJECT_ADDREMOVE), 824 | ))) 825 | } 826 | SIMCONNECT_RECV_ID_SIMCONNECT_RECV_ID_EVENT_FILENAME => { 827 | Ok(DispatchResult::EventFilename(transmute_copy( 828 | &(data_buf as *const SIMCONNECT_RECV_EVENT_FILENAME), 829 | ))) 830 | } 831 | SIMCONNECT_RECV_ID_SIMCONNECT_RECV_ID_EVENT_FRAME => { 832 | Ok(DispatchResult::EventFrame(transmute_copy( 833 | &(data_buf as *const SIMCONNECT_RECV_EVENT_FRAME), 834 | ))) 835 | } 836 | SIMCONNECT_RECV_ID_SIMCONNECT_RECV_ID_SIMOBJECT_DATA => { 837 | Ok(DispatchResult::SimObjectData(transmute_copy( 838 | &(data_buf as *const SIMCONNECT_RECV_SIMOBJECT_DATA), 839 | ))) 840 | } 841 | SIMCONNECT_RECV_ID_SIMCONNECT_RECV_ID_SIMOBJECT_DATA_BYTYPE => { 842 | Ok(DispatchResult::SimObjectDataByType(transmute_copy( 843 | &(data_buf as *const SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE), 844 | ))) 845 | } 846 | SIMCONNECT_RECV_ID_SIMCONNECT_RECV_ID_WEATHER_OBSERVATION => { 847 | Ok(DispatchResult::WeatherObservation(transmute_copy( 848 | &(data_buf as *const SIMCONNECT_RECV_WEATHER_OBSERVATION), 849 | ))) 850 | } 851 | SIMCONNECT_RECV_ID_SIMCONNECT_RECV_ID_CLOUD_STATE => { 852 | Ok(DispatchResult::CloudState(transmute_copy( 853 | &(data_buf as *const SIMCONNECT_RECV_CLOUD_STATE), 854 | ))) 855 | } 856 | SIMCONNECT_RECV_ID_SIMCONNECT_RECV_ID_ASSIGNED_OBJECT_ID => { 857 | Ok(DispatchResult::AssignedObjectId(transmute_copy( 858 | &(data_buf as *const SIMCONNECT_RECV_ASSIGNED_OBJECT_ID), 859 | ))) 860 | } 861 | SIMCONNECT_RECV_ID_SIMCONNECT_RECV_ID_RESERVED_KEY => { 862 | Ok(DispatchResult::ReservedKey(transmute_copy( 863 | &(data_buf as *const SIMCONNECT_RECV_RESERVED_KEY), 864 | ))) 865 | } 866 | SIMCONNECT_RECV_ID_SIMCONNECT_RECV_ID_CUSTOM_ACTION => { 867 | Ok(DispatchResult::CustomAction(transmute_copy( 868 | &(data_buf as *const SIMCONNECT_RECV_CUSTOM_ACTION), 869 | ))) 870 | } 871 | SIMCONNECT_RECV_ID_SIMCONNECT_RECV_ID_SYSTEM_STATE => { 872 | Ok(DispatchResult::SystemState(transmute_copy( 873 | &(data_buf as *const SIMCONNECT_RECV_SYSTEM_STATE), 874 | ))) 875 | } 876 | SIMCONNECT_RECV_ID_SIMCONNECT_RECV_ID_CLIENT_DATA => { 877 | Ok(DispatchResult::ClientData(transmute_copy( 878 | &(data_buf as *const SIMCONNECT_RECV_CLIENT_DATA), 879 | ))) 880 | } 881 | SIMCONNECT_RECV_ID_SIMCONNECT_RECV_ID_EVENT_WEATHER_MODE => { 882 | Ok(DispatchResult::EventWeatherMode(transmute_copy( 883 | &(data_buf as *const SIMCONNECT_RECV_EVENT_WEATHER_MODE), 884 | ))) 885 | } 886 | SIMCONNECT_RECV_ID_SIMCONNECT_RECV_ID_AIRPORT_LIST => { 887 | Ok(DispatchResult::AirportList(transmute_copy( 888 | &(data_buf as *const SIMCONNECT_RECV_AIRPORT_LIST), 889 | ))) 890 | } 891 | SIMCONNECT_RECV_ID_SIMCONNECT_RECV_ID_VOR_LIST => Ok(DispatchResult::VorList( 892 | transmute_copy(&(data_buf as *const SIMCONNECT_RECV_VOR_LIST)), 893 | )), 894 | SIMCONNECT_RECV_ID_SIMCONNECT_RECV_ID_NDB_LIST => Ok(DispatchResult::NdbList( 895 | transmute_copy(&(data_buf as *const SIMCONNECT_RECV_NDB_LIST)), 896 | )), 897 | SIMCONNECT_RECV_ID_SIMCONNECT_RECV_ID_WAYPOINT_LIST => { 898 | Ok(DispatchResult::WaypointList(transmute_copy( 899 | &(data_buf as *const SIMCONNECT_RECV_WAYPOINT_LIST), 900 | ))) 901 | } 902 | SIMCONNECT_RECV_ID_SIMCONNECT_RECV_ID_EVENT_MULTIPLAYER_SERVER_STARTED => Ok( 903 | DispatchResult::EventMultiplayerServerStarted(transmute_copy( 904 | &(data_buf as *const SIMCONNECT_RECV_EVENT_MULTIPLAYER_SERVER_STARTED), 905 | )), 906 | ), 907 | SIMCONNECT_RECV_ID_SIMCONNECT_RECV_ID_EVENT_MULTIPLAYER_CLIENT_STARTED => Ok( 908 | DispatchResult::EventMultiplayerClientStarted(transmute_copy( 909 | &(data_buf as *const SIMCONNECT_RECV_EVENT_MULTIPLAYER_CLIENT_STARTED), 910 | )), 911 | ), 912 | SIMCONNECT_RECV_ID_SIMCONNECT_RECV_ID_EVENT_MULTIPLAYER_SESSION_ENDED => Ok( 913 | DispatchResult::EventMultiplayerSessionEnded(transmute_copy( 914 | &(data_buf as *const SIMCONNECT_RECV_EVENT_MULTIPLAYER_SESSION_ENDED), 915 | )), 916 | ), 917 | SIMCONNECT_RECV_ID_SIMCONNECT_RECV_ID_EVENT_RACE_END => { 918 | Ok(DispatchResult::EventRaceEnd(transmute_copy( 919 | &(data_buf as *const SIMCONNECT_RECV_EVENT_RACE_END), 920 | ))) 921 | } 922 | SIMCONNECT_RECV_ID_SIMCONNECT_RECV_ID_EVENT_RACE_LAP => { 923 | Ok(DispatchResult::EventRaceLap(transmute_copy( 924 | &(data_buf as *const SIMCONNECT_RECV_EVENT_RACE_LAP), 925 | ))) 926 | } 927 | 928 | _ => Err("Unhandled RECV_ID"), 929 | }; 930 | } 931 | } 932 | } 933 | 934 | impl Drop for SimConnector { 935 | fn drop(&mut self) { 936 | if !self.sim_connect_handle.is_null() { 937 | self.close(); 938 | } 939 | } 940 | } 941 | --------------------------------------------------------------------------------