├── .gitattributes
├── .gitignore
├── .gitmodules
├── LICENSE.txt
├── README.md
├── Request_collection.har
├── Request_collection_insomnia.json
├── X4_Rest_Reloaded.postman_collection.json
├── X4_Rest_Reloaded.sln
└── X4_Rest_Reloaded
├── .clang-format
├── InitHelper.h
├── X4_Rest_Reloaded.vcxproj
├── X4_Rest_Reloaded.vcxproj.filters
├── _lua_.h
├── asm.asm
├── dllmain.cpp
├── endpoint_impl
├── common_funcs.h
├── logbook_funcs.h
├── map_or_query_funcs.h
├── message_funcs.h
├── object_and_component_funcs.h
└── player_funcs.h
├── ffi
├── FFIInvoke.cpp
├── FFIInvoke.h
├── ffi_enum_helper.h
├── json_converters.h
└── x4ffi
│ ├── ffi_funcs.h
│ ├── ffi_funcs_customgame.h
│ ├── ffi_funcs_helper.h
│ ├── ffi_funcs_menu_map.h
│ ├── ffi_funcs_menu_playerinfo.h
│ ├── ffi_funcs_station_config.h
│ ├── ffi_typedef.h
│ └── ffi_typedef_struct.h
├── httpserver
├── HttpServer.cpp
└── HttpServer.h
└── lua_scripts
├── ComponentDataHelper.h
├── dump_lua.h
└── json.h
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Mono auto generated files
17 | mono_crash.*
18 |
19 | # Build results
20 | [Dd]ebug/
21 | [Dd]ebugPublic/
22 | [Rr]elease/
23 | [Rr]eleases/
24 | x64/
25 | x86/
26 | [Ww][Ii][Nn]32/
27 | [Aa][Rr][Mm]/
28 | [Aa][Rr][Mm]64/
29 | bld/
30 | [Bb]in/
31 | [Oo]bj/
32 | [Oo]ut/
33 | [Ll]og/
34 | [Ll]ogs/
35 |
36 | # Visual Studio 2015/2017 cache/options directory
37 | .vs/
38 | # Uncomment if you have tasks that create the project's static files in wwwroot
39 | #wwwroot/
40 |
41 | # Visual Studio 2017 auto generated files
42 | Generated\ Files/
43 |
44 | # MSTest test Results
45 | [Tt]est[Rr]esult*/
46 | [Bb]uild[Ll]og.*
47 |
48 | # NUnit
49 | *.VisualState.xml
50 | TestResult.xml
51 | nunit-*.xml
52 |
53 | # Build Results of an ATL Project
54 | [Dd]ebugPS/
55 | [Rr]eleasePS/
56 | dlldata.c
57 |
58 | # Benchmark Results
59 | BenchmarkDotNet.Artifacts/
60 |
61 | # .NET Core
62 | project.lock.json
63 | project.fragment.lock.json
64 | artifacts/
65 |
66 | # ASP.NET Scaffolding
67 | ScaffoldingReadMe.txt
68 |
69 | # StyleCop
70 | StyleCopReport.xml
71 |
72 | # Files built by Visual Studio
73 | *_i.c
74 | *_p.c
75 | *_h.h
76 | *.ilk
77 | *.meta
78 | *.obj
79 | *.iobj
80 | *.pch
81 | *.pdb
82 | *.ipdb
83 | *.pgc
84 | *.pgd
85 | *.rsp
86 | *.sbr
87 | *.tlb
88 | *.tli
89 | *.tlh
90 | *.tmp
91 | *.tmp_proj
92 | *_wpftmp.csproj
93 | *.log
94 | *.vspscc
95 | *.vssscc
96 | .builds
97 | *.pidb
98 | *.svclog
99 | *.scc
100 |
101 | # Chutzpah Test files
102 | _Chutzpah*
103 |
104 | # Visual C++ cache files
105 | ipch/
106 | *.aps
107 | *.ncb
108 | *.opendb
109 | *.opensdf
110 | *.sdf
111 | *.cachefile
112 | *.VC.db
113 | *.VC.VC.opendb
114 |
115 | # Visual Studio profiler
116 | *.psess
117 | *.vsp
118 | *.vspx
119 | *.sap
120 |
121 | # Visual Studio Trace Files
122 | *.e2e
123 |
124 | # TFS 2012 Local Workspace
125 | $tf/
126 |
127 | # Guidance Automation Toolkit
128 | *.gpState
129 |
130 | # ReSharper is a .NET coding add-in
131 | _ReSharper*/
132 | *.[Rr]e[Ss]harper
133 | *.DotSettings.user
134 |
135 | # TeamCity is a build add-in
136 | _TeamCity*
137 |
138 | # DotCover is a Code Coverage Tool
139 | *.dotCover
140 |
141 | # AxoCover is a Code Coverage Tool
142 | .axoCover/*
143 | !.axoCover/settings.json
144 |
145 | # Coverlet is a free, cross platform Code Coverage Tool
146 | coverage*.json
147 | coverage*.xml
148 | coverage*.info
149 |
150 | # Visual Studio code coverage results
151 | *.coverage
152 | *.coveragexml
153 |
154 | # NCrunch
155 | _NCrunch_*
156 | .*crunch*.local.xml
157 | nCrunchTemp_*
158 |
159 | # MightyMoose
160 | *.mm.*
161 | AutoTest.Net/
162 |
163 | # Web workbench (sass)
164 | .sass-cache/
165 |
166 | # Installshield output folder
167 | [Ee]xpress/
168 |
169 | # DocProject is a documentation generator add-in
170 | DocProject/buildhelp/
171 | DocProject/Help/*.HxT
172 | DocProject/Help/*.HxC
173 | DocProject/Help/*.hhc
174 | DocProject/Help/*.hhk
175 | DocProject/Help/*.hhp
176 | DocProject/Help/Html2
177 | DocProject/Help/html
178 |
179 | # Click-Once directory
180 | publish/
181 |
182 | # Publish Web Output
183 | *.[Pp]ublish.xml
184 | *.azurePubxml
185 | # Note: Comment the next line if you want to checkin your web deploy settings,
186 | # but database connection strings (with potential passwords) will be unencrypted
187 | *.pubxml
188 | *.publishproj
189 |
190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
191 | # checkin your Azure Web App publish settings, but sensitive information contained
192 | # in these scripts will be unencrypted
193 | PublishScripts/
194 |
195 | # NuGet Packages
196 | *.nupkg
197 | # NuGet Symbol Packages
198 | *.snupkg
199 | # The packages folder can be ignored because of Package Restore
200 | **/[Pp]ackages/*
201 | # except build/, which is used as an MSBuild target.
202 | !**/[Pp]ackages/build/
203 | # Uncomment if necessary however generally it will be regenerated when needed
204 | #!**/[Pp]ackages/repositories.config
205 | # NuGet v3's project.json files produces more ignorable files
206 | *.nuget.props
207 | *.nuget.targets
208 |
209 | # Microsoft Azure Build Output
210 | csx/
211 | *.build.csdef
212 |
213 | # Microsoft Azure Emulator
214 | ecf/
215 | rcf/
216 |
217 | # Windows Store app package directories and files
218 | AppPackages/
219 | BundleArtifacts/
220 | Package.StoreAssociation.xml
221 | _pkginfo.txt
222 | *.appx
223 | *.appxbundle
224 | *.appxupload
225 |
226 | # Visual Studio cache files
227 | # files ending in .cache can be ignored
228 | *.[Cc]ache
229 | # but keep track of directories ending in .cache
230 | !?*.[Cc]ache/
231 |
232 | # Others
233 | ClientBin/
234 | ~$*
235 | *~
236 | *.dbmdl
237 | *.dbproj.schemaview
238 | *.jfm
239 | *.pfx
240 | *.publishsettings
241 | orleans.codegen.cs
242 |
243 | # Including strong name files can present a security risk
244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
245 | #*.snk
246 |
247 | # Since there are multiple workflows, uncomment next line to ignore bower_components
248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
249 | #bower_components/
250 |
251 | # RIA/Silverlight projects
252 | Generated_Code/
253 |
254 | # Backup & report files from converting an old project file
255 | # to a newer Visual Studio version. Backup files are not needed,
256 | # because we have git ;-)
257 | _UpgradeReport_Files/
258 | Backup*/
259 | UpgradeLog*.XML
260 | UpgradeLog*.htm
261 | ServiceFabricBackup/
262 | *.rptproj.bak
263 |
264 | # SQL Server files
265 | *.mdf
266 | *.ldf
267 | *.ndf
268 |
269 | # Business Intelligence projects
270 | *.rdl.data
271 | *.bim.layout
272 | *.bim_*.settings
273 | *.rptproj.rsuser
274 | *- [Bb]ackup.rdl
275 | *- [Bb]ackup ([0-9]).rdl
276 | *- [Bb]ackup ([0-9][0-9]).rdl
277 |
278 | # Microsoft Fakes
279 | FakesAssemblies/
280 |
281 | # GhostDoc plugin setting file
282 | *.GhostDoc.xml
283 |
284 | # Node.js Tools for Visual Studio
285 | .ntvs_analysis.dat
286 | node_modules/
287 |
288 | # Visual Studio 6 build log
289 | *.plg
290 |
291 | # Visual Studio 6 workspace options file
292 | *.opt
293 |
294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
295 | *.vbw
296 |
297 | # Visual Studio LightSwitch build output
298 | **/*.HTMLClient/GeneratedArtifacts
299 | **/*.DesktopClient/GeneratedArtifacts
300 | **/*.DesktopClient/ModelManifest.xml
301 | **/*.Server/GeneratedArtifacts
302 | **/*.Server/ModelManifest.xml
303 | _Pvt_Extensions
304 |
305 | # Paket dependency manager
306 | .paket/paket.exe
307 | paket-files/
308 |
309 | # FAKE - F# Make
310 | .fake/
311 |
312 | # CodeRush personal settings
313 | .cr/personal
314 |
315 | # Python Tools for Visual Studio (PTVS)
316 | __pycache__/
317 | *.pyc
318 |
319 | # Cake - Uncomment if you are using it
320 | # tools/**
321 | # !tools/packages.config
322 |
323 | # Tabs Studio
324 | *.tss
325 |
326 | # Telerik's JustMock configuration file
327 | *.jmconfig
328 |
329 | # BizTalk build output
330 | *.btp.cs
331 | *.btm.cs
332 | *.odx.cs
333 | *.xsd.cs
334 |
335 | # OpenCover UI analysis results
336 | OpenCover/
337 |
338 | # Azure Stream Analytics local run output
339 | ASALocalRun/
340 |
341 | # MSBuild Binary and Structured Log
342 | *.binlog
343 |
344 | # NVidia Nsight GPU debugger configuration file
345 | *.nvuser
346 |
347 | # MFractors (Xamarin productivity tool) working folder
348 | .mfractor/
349 |
350 | # Local History for Visual Studio
351 | .localhistory/
352 |
353 | # BeatPulse healthcheck temp database
354 | healthchecksdb
355 |
356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
357 | MigrationBackup/
358 |
359 | # Ionide (cross platform F# VS Code tools) working folder
360 | .ionide/
361 |
362 | # Fody - auto-generated XML schema
363 | FodyWeavers.xsd
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "deps/cpp-httplib"]
2 | path = deps/cpp-httplib
3 | url = https://github.com/yhirose/cpp-httplib.git
4 | [submodule "deps/json"]
5 | path = deps/json
6 | url = https://github.com/nlohmann/json.git
7 | [submodule "deps/subhook"]
8 | path = deps/subhook
9 | url = git@github.com:Zeex/subhook.git
10 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023 Peter Repukat - Flatspot-Software
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.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # X4 Rest Server
2 |
3 | ## Project reboot
4 |
5 | Stay tuned.
6 |
--------------------------------------------------------------------------------
/X4_Rest_Reloaded.postman_collection.json:
--------------------------------------------------------------------------------
1 | {"info":{"_postman_id":"eb4cfc55-9a0a-4817-9dde-f5861b48ee64","name":"requests","schema":"https://schema.getpostman.com/json/collection/v2.1.0/collection.json"},"item":[{"name":"/GetPlayerComputerID","request":{"description":"","method":"GET","header":[],"url":{"raw":"{{ _.baseUrl }}/GetPlayerComputerID","host":["{{ _","baseUrl }}"],"path":["GetPlayerComputerID"]},"auth":{}},"response":[]},{"name":"/stop","request":{"description":"","method":"POST","header":[],"url":{"raw":"{{ _.baseUrl }}/stop","host":["{{ _","baseUrl }}"],"path":["stop"]},"auth":{}},"response":[]},{"name":"/GetPlayerContainerID","request":{"description":"","method":"GET","header":[],"url":{"raw":"{{ _.baseUrl }}/GetPlayerContainerID","host":["{{ _","baseUrl }}"],"path":["GetPlayerContainerID"]},"auth":{}},"response":[]},{"name":"/GetPlayerControlledShipID","request":{"description":"","method":"GET","header":[],"url":{"raw":"{{ _.baseUrl }}/GetPlayerControlledShipID","host":["{{ _","baseUrl }}"],"path":["GetPlayerControlledShipID"]},"auth":{}},"response":[]},{"name":"/GetPlayerID","request":{"description":"","method":"GET","header":[],"url":{"raw":"{{ _.baseUrl }}/GetPlayerID","host":["{{ _","baseUrl }}"],"path":["GetPlayerID"]},"auth":{}},"response":[]},{"name":"/GetPlayerObjectID","request":{"description":"","method":"GET","header":[],"url":{"raw":"{{ _.baseUrl }}/GetPlayerObjectID","host":["{{ _","baseUrl }}"],"path":["GetPlayerObjectID"]},"auth":{}},"response":[]},{"name":"/GetPlayerOccupiedShipID","request":{"description":"","method":"GET","header":[],"url":{"raw":"{{ _.baseUrl }}/GetPlayerOccupiedShipID","host":["{{ _","baseUrl }}"],"path":["GetPlayerOccupiedShipID"]},"auth":{}},"response":[]},{"name":"/","request":{"description":"","method":"GET","header":[],"url":{"raw":"{{ _.baseUrl }}/","host":["{{ _","baseUrl }}/"],"path":[]},"auth":{}},"response":[]},{"name":"/GetPlayerName","request":{"description":"","method":"GET","header":[],"url":{"raw":"{{ _.baseUrl }}/GetPlayerName","host":["{{ _","baseUrl }}"],"path":["GetPlayerName"]},"auth":{}},"response":[]},{"name":"/GetPlayerFactionName","request":{"description":"","method":"GET","header":[],"url":{"raw":"{{ _.baseUrl }}/GetPlayerFactionName","query":[{"key":"userawname","value":"true"}],"host":["{{ _","baseUrl }}"],"path":["GetPlayerFactionName"]},"auth":{}},"response":[]},{"name":"/GetPlayerZoneID","request":{"description":"","method":"GET","header":[],"url":{"raw":"{{ _.baseUrl }}/GetPlayerZoneID","host":["{{ _","baseUrl }}"],"path":["GetPlayerZoneID"]},"auth":{}},"response":[]},{"name":"/GetCurrentGameTime","request":{"description":"","method":"GET","header":[],"url":{"raw":"{{ _.baseUrl }}/GetCurrentGameTime","host":["{{ _","baseUrl }}"],"path":["GetCurrentGameTime"]},"auth":{}},"response":[]},{"name":"/GetNumMessages","request":{"description":"","method":"GET","header":[],"url":{"raw":"{{ _.baseUrl }}/GetNumMessages","query":[{"key":"category","value":"all"},{"key":"unread","value":"false"}],"host":["{{ _","baseUrl }}"],"path":["GetNumMessages"]},"auth":{}},"response":[]},{"name":"/GetMessages","request":{"description":"","method":"GET","header":[],"url":{"raw":"{{ _.baseUrl }}/GetMessages","query":[{"key":"category","value":"all"},{"key":"from","value":"0"},{"key":"count","value":"99999"},{"key":"","value":""}],"host":["{{ _","baseUrl }}"],"path":["GetMessages"]},"auth":{}},"response":[]},{"name":"/DumpLua","request":{"description":"","method":"GET","header":[],"url":{"raw":"{{ _.baseUrl }}/DumpLua","host":["{{ _","baseUrl }}"],"path":["DumpLua"]},"auth":{}},"response":[]},{"name":"/Pause","request":{"description":"","method":"POST","header":[],"url":{"raw":"{{ _.baseUrl }}/Pause","host":["{{ _","baseUrl }}"],"path":["Pause"]},"auth":{}},"response":[]},{"name":"/Unpause","request":{"description":"","method":"POST","header":[],"url":{"raw":"{{ _.baseUrl }}/Unpause","host":["{{ _","baseUrl }}"],"path":["Unpause"]},"auth":{}},"response":[]},{"name":"/GetNumLogbook","request":{"description":"","method":"GET","header":[],"url":{"raw":"{{ _.baseUrl }}/GetNumLogbook","query":[{"key":"category","value":"all"},{"key":"","value":""}],"host":["{{ _","baseUrl }}"],"path":["GetNumLogbook"]},"auth":{}},"response":[]},{"name":"/GetLogbook","request":{"description":"","method":"GET","header":[],"url":{"raw":"{{ _.baseUrl }}/GetLogbook","query":[{"key":"category","value":"all"},{"key":"page","value":"0"}],"host":["{{ _","baseUrl }}"],"path":["GetLogbook"]},"auth":{}},"response":[]},{"name":"/GetObjectIDCode","request":{"description":"","method":"GET","header":[],"url":{"raw":"{{ _.baseUrl }}/GetObjectIDCode","query":[{"key":"\"objectId\"","value":"227873"}],"host":["{{ _","baseUrl }}"],"path":["GetObjectIDCode"]},"auth":{}},"response":[]},{"name":"/GetComponentClass","request":{"description":"","method":"GET","header":[],"url":{"raw":"{{ _.baseUrl }}/GetComponentClass","query":[{"key":"\"componentId\"","value":"227873"}],"host":["{{ _","baseUrl }}"],"path":["GetComponentClass"]},"auth":{}},"response":[]},{"name":"/GetComponentName","request":{"description":"","method":"GET","header":[],"url":{"raw":"{{ _.baseUrl }}/GetComponentName","query":[{"key":"componentId","value":"230305"}],"host":["{{ _","baseUrl }}"],"path":["GetComponentName"]},"auth":{}},"response":[]},{"name":"/ExecuteLuaScript","request":{"description":"","method":"POST","header":[{"key":"Content-Type","value":"text/plain"}],"body":{"mode":"raw","raw":"github.com/Vyoam/InsomniaToPostmanFormat: Unsupported body type text/plain"},"url":{"raw":"{{ _.baseUrl }}/ExecuteLuaScript","host":["{{ _","baseUrl }}"],"path":["ExecuteLuaScript"]},"auth":{}},"response":[]},{"name":"/GetComponentData","request":{"description":"","method":"GET","header":[],"url":{"raw":"{{ _.baseUrl }}/GetComponentData","query":[{"key":"componentId","value":"230301"},{"key":"attribs","value":"name,hullpercent,shieldpercent,sector,isdock,maxunboostedforwardspeed"}],"host":["{{ _","baseUrl }}"],"path":["GetComponentData"]},"auth":{}},"response":[]},{"name":"/GetStats","request":{"description":"","method":"GET","header":[],"url":{"raw":"{{ _.baseUrl }}/GetStats","query":[{"key":"hidden","value":"0"}],"host":["{{ _","baseUrl }}"],"path":["GetStats"]},"auth":{}},"response":[]},{"name":"/GetCurrentUTCDataTime","request":{"description":"","method":"GET","header":[],"url":{"raw":"{{ _.baseUrl }}/GetCurrentUTCDataTime","host":["{{ _","baseUrl }}"],"path":["GetCurrentUTCDataTime"]},"auth":{}},"response":[]},{"name":"/GetObjectPositionInSector","request":{"description":"","method":"GET","header":[],"url":{"raw":"{{ _.baseUrl }}/GetObjectPositionInSector","query":[{"key":"objectId","value":"229140"}],"host":["{{ _","baseUrl }}"],"path":["GetObjectPositionInSector"]},"auth":{}},"response":[]},{"name":"/GetPlayerTargetOffset","request":{"description":"","method":"GET","header":[],"url":{"raw":"{{ _.baseUrl }}/GetPlayerTargetOffset","host":["{{ _","baseUrl }}"],"path":["GetPlayerTargetOffset"]},"auth":{}},"response":[]},{"name":"/GetCreditsDueFromPlayerBuilds","request":{"description":"","method":"GET","header":[],"url":{"raw":"{{ _.baseUrl }}/GetCreditsDueFromPlayerBuilds","host":["{{ _","baseUrl }}"],"path":["GetCreditsDueFromPlayerBuilds"]},"auth":{}},"response":[]},{"name":"/GetCreditsDueFromPlayerTrades","request":{"description":"","method":"GET","header":[],"url":{"raw":"{{ _.baseUrl }}/GetCreditsDueFromPlayerTrades","host":["{{ _","baseUrl }}"],"path":["GetCreditsDueFromPlayerTrades"]},"auth":{}},"response":[]},{"name":"/GetSofttarget","request":{"description":"","method":"GET","header":[],"url":{"raw":"{{ _.baseUrl }}/GetSofttarget","host":["{{ _","baseUrl }}"],"path":["GetSofttarget"]},"auth":{}},"response":[]},{"name":"/IsObjectKnown","request":{"description":"","method":"GET","header":[],"url":{"raw":"{{ _.baseUrl }}/IsObjectKnown","query":[{"key":"componentId","value":"229140"}],"host":["{{ _","baseUrl }}"],"path":["IsObjectKnown"]},"auth":{}},"response":[]},{"name":"/GetNumAllRaces","request":{"description":"","method":"GET","header":[],"url":{"raw":"{{ _.baseUrl }}/GetNumAllRaces","query":[{"key":"category","value":"all"},{"key":"page","value":"0"}],"host":["{{ _","baseUrl }}"],"path":["GetNumAllRaces"]},"auth":{}},"response":[]},{"name":"/GetAllRaces","request":{"description":"","method":"GET","header":[],"url":{"raw":"{{ _.baseUrl }}/GetAllRaces","query":[{"key":"category","value":"all"},{"key":"page","value":"0"}],"host":["{{ _","baseUrl }}"],"path":["GetAllRaces"]},"auth":{}},"response":[]},{"name":"/GetNumAllFactions","request":{"description":"","method":"GET","header":[],"url":{"raw":"{{ _.baseUrl }}/GetNumAllFactions","query":[{"key":"category","value":"all"},{"key":"page","value":"0"}],"host":["{{ _","baseUrl }}"],"path":["GetNumAllFactions"]},"auth":{}},"response":[]},{"name":"/GetAllFactions","request":{"description":"","method":"GET","header":[],"url":{"raw":"{{ _.baseUrl }}/GetAllFactions","query":[{"key":"hidden","value":"0"}],"host":["{{ _","baseUrl }}"],"path":["GetAllFactions"]},"auth":{}},"response":[]},{"name":"/GetAllFactionShips","request":{"description":"","method":"GET","header":[],"url":{"raw":"{{ _.baseUrl }}/GetAllFactionShips","query":[{"key":"factionId","value":"argon"}],"host":["{{ _","baseUrl }}"],"path":["GetAllFactionShips"]},"auth":{}},"response":[]},{"name":"/GetAllFactionStations","request":{"description":"","method":"GET","header":[],"url":{"raw":"{{ _.baseUrl }}/GetAllFactionStations","query":[{"key":"factionId","value":"argon"}],"host":["{{ _","baseUrl }}"],"path":["GetAllFactionStations"]},"auth":{}},"response":[]}]}
--------------------------------------------------------------------------------
/X4_Rest_Reloaded.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.4.33213.308
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "X4_Rest_Reloaded", "X4_Rest_Reloaded\X4_Rest_Reloaded.vcxproj", "{1EA05768-2EA9-4950-82D1-03FC4F47F1EA}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {1EA05768-2EA9-4950-82D1-03FC4F47F1EA}.Debug|x64.ActiveCfg = Debug|x64
17 | {1EA05768-2EA9-4950-82D1-03FC4F47F1EA}.Debug|x64.Build.0 = Debug|x64
18 | {1EA05768-2EA9-4950-82D1-03FC4F47F1EA}.Debug|x86.ActiveCfg = Debug|Win32
19 | {1EA05768-2EA9-4950-82D1-03FC4F47F1EA}.Debug|x86.Build.0 = Debug|Win32
20 | {1EA05768-2EA9-4950-82D1-03FC4F47F1EA}.Release|x64.ActiveCfg = Release|x64
21 | {1EA05768-2EA9-4950-82D1-03FC4F47F1EA}.Release|x64.Build.0 = Release|x64
22 | {1EA05768-2EA9-4950-82D1-03FC4F47F1EA}.Release|x86.ActiveCfg = Release|Win32
23 | {1EA05768-2EA9-4950-82D1-03FC4F47F1EA}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(ExtensibilityGlobals) = postSolution
29 | SolutionGuid = {1184035A-EB4F-46FF-A404-33C3D5C4C932}
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------
/X4_Rest_Reloaded/.clang-format:
--------------------------------------------------------------------------------
1 | # Visual Studio generated .clang-format file
2 |
3 | # The style options in this file are a best effort attempt to replicate the
4 | # current IDE formatting configuration from Tools > Options. The following
5 | # style options, however, should be verified:
6 | # AfterClass, AfterControlStatement, AfterEnum, AfterFunction, AfterNamespace,
7 | # AfterStruct, AfterUnion
8 |
9 | UseTab: false
10 | #BasedOnStyle: LLVM
11 | #IndentWidth: 4
12 | BreakBeforeBraces: "Stroustrup"
13 | AllowShortIfStatementsOnASingleLine: false
14 | #IndentCaseLabels: false
15 | ColumnLimit: 96
16 | #PointerAlignment: "Left"
17 | #NamespaceIndentation: All
18 | SortIncludes: "Never"
19 |
20 |
21 |
22 | AccessModifierOffset: -4
23 | AlignAfterOpenBracket: DontAlign
24 | AllowShortBlocksOnASingleLine: true
25 | AllowShortFunctionsOnASingleLine: All
26 | BasedOnStyle: LLVM
27 | BraceWrapping:
28 | AfterClass: false # TODO: verify
29 | AfterControlStatement: false # TODO: verify
30 | AfterEnum: false # TODO: verify
31 | AfterFunction: false # TODO: verify
32 | AfterNamespace: false # TODO: verify
33 | AfterStruct: false # TODO: verify
34 | AfterUnion: false # TODO: verify
35 | BeforeCatch: true
36 | BeforeElse: true
37 | IndentBraces: false
38 | SplitEmptyFunction: true
39 | SplitEmptyRecord: true
40 | BreakBeforeBraces: Custom
41 | #ColumnLimit: 0
42 | Cpp11BracedListStyle: true
43 | FixNamespaceComments: false
44 | IndentCaseLabels: false
45 | IndentPPDirectives: None
46 | IndentWidth: 4
47 | MaxEmptyLinesToKeep: 10
48 | NamespaceIndentation: All
49 | PointerAlignment: Left
50 | SortUsingDeclarations: false
51 | SpaceAfterCStyleCast: false
52 | SpaceBeforeAssignmentOperators: true
53 | SpaceBeforeParens: ControlStatements
54 | SpaceInEmptyParentheses: false
55 | SpacesInCStyleCastParentheses: false
56 | SpacesInParentheses: false
57 | SpacesInSquareBrackets: true
58 | TabWidth: 4
--------------------------------------------------------------------------------
/X4_Rest_Reloaded/InitHelper.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2021-2023 Peter Repukat - FlatspotSoftware
3 |
4 | Use of this source code is governed by the MIT
5 | license that can be found in the LICENSE file or at
6 | https://opensource.org/licenses/MIT.
7 | */
8 |
9 | #pragma once
10 | #include "endpoint_impl/common_funcs.h"
11 | #include "endpoint_impl/logbook_funcs.h"
12 | #include "endpoint_impl/map_or_query_funcs.h"
13 | #include "endpoint_impl/message_funcs.h"
14 | #include "endpoint_impl/object_and_component_funcs.h"
15 | #include "endpoint_impl/player_funcs.h"
16 |
17 | class FFIInvoke;
18 |
19 | class InitHelper {
20 | public:
21 | static inline void init(FFIInvoke& ffi_invoke) {
22 | RegisterCommonFunctions(ffi_invoke);
23 | RegisterPlayerFunctions(ffi_invoke);
24 | RegisterMessageFunctions(ffi_invoke);
25 | RegisterLogbookFunctions(ffi_invoke);
26 | RegisterObjectAndComponentFunctions(ffi_invoke);
27 | RegisterMapOrQueryFunctions(ffi_invoke);
28 | }
29 | };
30 |
31 | ;
32 |
--------------------------------------------------------------------------------
/X4_Rest_Reloaded/X4_Rest_Reloaded.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 | Debug
14 | x64
15 |
16 |
17 | Release
18 | x64
19 |
20 |
21 |
22 | 16.0
23 | Win32Proj
24 | {1ea05768-2ea9-4950-82d1-03fc4f47f1ea}
25 | X4RestReloaded
26 | 10.0
27 |
28 |
29 |
30 | DynamicLibrary
31 | true
32 | v143
33 | Unicode
34 |
35 |
36 | DynamicLibrary
37 | false
38 | v143
39 | true
40 | Unicode
41 |
42 |
43 | DynamicLibrary
44 | true
45 | v143
46 | Unicode
47 |
48 |
49 | DynamicLibrary
50 | false
51 | v143
52 | true
53 | Unicode
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 | $(SolutionDir)deps\cpp-httplib;$(SolutionDir)deps\json\include;$(SolutionDir)deps\subhook;$(IncludePath)
76 |
77 |
78 | $(SolutionDir)deps\cpp-httplib;$(SolutionDir)deps\json\include;$(SolutionDir)deps\subhook;$(IncludePath)
79 |
80 |
81 |
82 | Level3
83 | true
84 | WIN32;_DEBUG;X4RESTRELOADED_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)
85 | true
86 | Use
87 | pch.h
88 |
89 |
90 | Windows
91 | true
92 | false
93 |
94 |
95 |
96 |
97 | Level3
98 | true
99 | true
100 | true
101 | WIN32;NDEBUG;X4RESTRELOADED_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)
102 | true
103 | Use
104 | pch.h
105 |
106 |
107 | Windows
108 | true
109 | true
110 | true
111 | false
112 |
113 |
114 |
115 |
116 | Level3
117 | true
118 | SUBHOOK_STATIC;_DEBUG;X4RESTRELOADED_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)
119 | true
120 | NotUsing
121 |
122 |
123 | stdcpp20
124 | Async
125 |
126 |
127 | Windows
128 | true
129 | false
130 |
131 |
132 |
133 |
134 | Level3
135 | true
136 | true
137 | true
138 | SUBHOOK_STATIC;NDEBUG;X4RESTRELOADED_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)
139 | true
140 | NotUsing
141 |
142 |
143 | stdcpp20
144 | Async
145 |
146 |
147 | Windows
148 | true
149 | true
150 | true
151 | false
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 | Document
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
--------------------------------------------------------------------------------
/X4_Rest_Reloaded/X4_Rest_Reloaded.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 | {97759260-5627-4be8-b908-ed699e278132}
18 |
19 |
20 | {6dab583b-fb8d-497f-8644-e1b507e9a52d}
21 |
22 |
23 | {6bdb67f2-cabf-4fb5-9e06-3a3e1f9569a5}
24 |
25 |
26 | {2bb62194-14ae-49ec-83f9-80bd9bd57885}
27 |
28 |
29 |
30 |
31 | Source Files
32 |
33 |
34 | Source Files\httpserver
35 |
36 |
37 | Source Files\ffi
38 |
39 |
40 | Source Files
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Header Files\httpserver
51 |
52 |
53 | Header Files\ffi
54 |
55 |
56 | Header Files
57 |
58 |
59 | Header Files
60 |
61 |
62 | Header Files
63 |
64 |
65 | Header Files
66 |
67 |
68 | Header Files
69 |
70 |
71 | Header Files
72 |
73 |
74 | Header Files
75 |
76 |
77 | Header Files
78 |
79 |
80 | Header Files
81 |
82 |
83 | Header Files
84 |
85 |
86 | Header Files
87 |
88 |
89 | Header Files
90 |
91 |
92 | Header Files
93 |
94 |
95 | Header Files
96 |
97 |
98 | Header Files
99 |
100 |
101 | Header Files
102 |
103 |
104 | Header Files
105 |
106 |
107 | Header Files
108 |
109 |
110 | Header Files
111 |
112 |
113 | Header Files
114 |
115 |
116 | Header Files
117 |
118 |
119 |
120 |
121 | Source Files
122 |
123 |
124 |
--------------------------------------------------------------------------------
/X4_Rest_Reloaded/_lua_.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 |
4 | #include "lua_scripts/json.h"
5 |
6 | #define LUA_OK 0
7 | #define LUA_YIELD 1
8 | #define LUA_ERRRUN 2
9 | #define LUA_ERRSYNTAX 3
10 | #define LUA_ERRMEM 4
11 | #define LUA_ERRERR 5
12 |
13 | std::timed_mutex lua_state_mtx;
14 |
15 | typedef void* lua_State;
16 |
17 | lua_State* ui_lua_state = nullptr;
18 |
19 | using _lua_setfield = void (*)(lua_State* L, int idx, const char* k);
20 | _lua_setfield lua_setfield;
21 |
22 | using _lua_getfield = void (*)(lua_State* L, int idx, const char* k);
23 | _lua_getfield lua_getfield;
24 |
25 | using _lua_close = void (*)(lua_State* L);
26 | _lua_close lua_close;
27 |
28 |
29 | using _luaL_loadfilex = int (*)(lua_State* L, const char* filename, const char* mode);
30 | _luaL_loadfilex luaL_loadfilex;
31 |
32 | using _lua_pcall = int (*)(lua_State* L, int nargs, int nresults, int errfunc);
33 | _lua_pcall lua_pcall;
34 |
35 | using _lua_tolstring = const char* (*)(lua_State* L, int idx, size_t* len);
36 | _lua_tolstring lua_tolstring;
37 |
38 | using _lua_settop = void (*)(lua_State* L, int idx);
39 | _lua_settop lua_settop;
40 |
41 | using _luaL_loadstring = int (*)(lua_State* L, const char* s);
42 | _luaL_loadstring luaL_loadstring;
43 |
44 | using _lua_getmetatable = int (*)(lua_State* L, int idx);
45 | _lua_getmetatable lua_getmetatable;
46 |
47 |
48 | using _lua_newthread = lua_State* (*)(lua_State* L);
49 | _lua_newthread lua_newthread;
50 |
51 | using _lua_gettop = int (*)(lua_State* L);
52 | _lua_gettop lua_gettop;
53 |
54 |
55 | std::atomic toExecuteLuaString{};
56 | std::atomic lua_result{};
57 |
58 |
59 | subhook::Hook LuaSetFieldHook;
60 | subhook::Hook LuaCloseHook;
61 |
62 | subhook::Hook LuaGetFieldHook;
63 |
64 | void lua_setfield_hook(lua_State* L, int idx, const char* k) {
65 | // OutputDebugStringA((std::string("lua_setfield_hook: ") + k + " idx: " +
66 | // std::to_string(idx) + "\n").c_str());
67 | subhook::ScopedHookRemove remove(&LuaSetFieldHook);
68 | lua_setfield(L, idx, k);
69 |
70 | // correct lua state has functions from the UI.
71 | // UpdateFrame seems to be the last one that's called when loading
72 | // -10002 is magic number defined in lua_setglobal macro
73 | // see: lua src
74 | if (idx == -10002 && std::string(k) == "UpdateFrame") {
75 | const std::lock_guard lock(lua_state_mtx);
76 | // OutputDebugStringA("lua_setfield_hook; found_lua_state\n");
77 | ui_lua_state = L;
78 | }
79 | }
80 |
81 | void lua_close_hook(lua_State* L) {
82 | const std::lock_guard lock(lua_state_mtx);
83 | if (L == ui_lua_state) {
84 | // OutputDebugStringA("Lua_close_hook; ui_lua_state_closed\n");
85 | ui_lua_state = nullptr;
86 | }
87 | subhook::ScopedHookRemove remove(&LuaCloseHook);
88 | lua_close(L);
89 | }
90 |
91 | void lua_getfield_hook(lua_State* L, int idx, const char* k) {
92 | subhook::ScopedHookRemove remove(&LuaGetFieldHook);
93 | lua_getfield(L, idx, k);
94 | // "onUpdate" is called every frame; this makes sure we're in the correct game-thread
95 | if (L == ui_lua_state && std::string(k) == "onUpdate") {
96 | // OutputDebugStringA(
97 | // (std::string("lua_getfield_hook: ") + k + " idx: " + std::to_string(idx) + "\n")
98 | // .c_str());
99 |
100 | const auto lua_str = toExecuteLuaString.load();
101 | if (lua_str != nullptr) {
102 | const auto top = lua_gettop(L);
103 | if (luaL_loadstring(L, lua_str) == LUA_OK) {
104 | // OutputDebugStringA("Calling lua_string from http: calling lua\n");
105 | if (lua_pcall(L, 0, -1, 0) == LUA_OK) {
106 | const char* result = lua_tolstring(L, -1, nullptr);
107 |
108 | if (result == nullptr) {
109 | // OutputDebugStringA("Calling lua_string from http: storing
110 | // res 1\n");
111 | lua_result.store("true");
112 | }
113 | else {
114 | // OutputDebugStringA("Calling lua_string from http: storing
115 | // res 2\n");
116 | lua_result.store(result);
117 | }
118 | }
119 | else {
120 | // OutputDebugStringA("Calling lua_string from http: storing res
121 | // 3\n");
122 | lua_result.store("error executing lua");
123 | }
124 | auto newTop = lua_gettop(L);
125 | while (newTop != top) {
126 | lua_settop(L, -(1) - 1);
127 | newTop = lua_gettop(L);
128 | }
129 | }
130 | else {
131 | // OutputDebugStringA("Calling lua_string from http: storing res
132 | // 4\n");
133 | lua_result.store("error loading lua");
134 | }
135 | // OutputDebugStringA("Calling lua_string from http: resetting
136 | // lua_string\n");
137 | toExecuteLuaString.store(nullptr);
138 | }
139 | }
140 | }
141 |
142 | inline void loadLuaLib() {
143 | if (const auto lua_module = GetModuleHandle(L"lua51_64.dll")) {
144 | lua_setfield = (_lua_setfield)(GetProcAddress(lua_module, "lua_setfield"));
145 | lua_getfield = (_lua_getfield)(GetProcAddress(lua_module, "lua_getfield"));
146 | lua_close = (_lua_close)(GetProcAddress(lua_module, "lua_close"));
147 |
148 | luaL_loadfilex = (_luaL_loadfilex)GetProcAddress(lua_module, "luaL_loadfilex");
149 | lua_pcall = (_lua_pcall)GetProcAddress(lua_module, "lua_pcall");
150 | lua_tolstring = (_lua_tolstring)GetProcAddress(lua_module, "lua_tolstring");
151 | lua_settop = (_lua_settop)GetProcAddress(lua_module, "lua_settop");
152 | luaL_loadstring = (_luaL_loadstring)GetProcAddress(lua_module, "luaL_loadstring");
153 |
154 | lua_getmetatable = (_lua_getmetatable)GetProcAddress(lua_module, "lua_getmetatable");
155 |
156 | lua_newthread = (_lua_newthread)GetProcAddress(lua_module, "lua_newthread");
157 |
158 | lua_gettop = (_lua_gettop)GetProcAddress(lua_module, "lua_gettop");
159 |
160 | LuaSetFieldHook.Install(GetProcAddress(lua_module, "lua_setfield"), &lua_setfield_hook,
161 | subhook::HookFlags::HookFlag64BitOffset);
162 | LuaCloseHook.Install(GetProcAddress(lua_module, "lua_close"), &lua_close_hook,
163 | subhook::HookFlags::HookFlag64BitOffset);
164 |
165 | LuaGetFieldHook.Install(GetProcAddress(lua_module, "lua_getfield"), &lua_getfield_hook,
166 | subhook::HookFlags::HookFlag64BitOffset);
167 | }
168 | }
169 |
170 | inline std::string executeLua(
171 | const std::string& lua_code, bool include_json = true, bool encode_userdata = false) {
172 |
173 | std::stringstream threadIdStrStr;
174 | threadIdStrStr << std::this_thread::get_id();
175 |
176 | const auto start = std::chrono::high_resolution_clock::now();
177 | // OutputDebugStringA(
178 | (std::string("queuing lua execution: locking lua_state_mtx; threadId: ") +
179 | threadIdStrStr.str() + "\n")
180 | .c_str();
181 | if (!lua_state_mtx.try_lock_for(std::chrono::seconds(3))) {
182 | throw std::exception("Error: Timeout acquiring lua execution lock");
183 | }
184 | const std::lock_guard lock(lua_state_mtx, std::adopt_lock);
185 | if (ui_lua_state != nullptr) {
186 | // OutputDebugStringA("queuing lua execution: resetting lua result\n");
187 | lua_result.store(nullptr);
188 | std::string lua_str =
189 | include_json ? (GetJsonLua(encode_userdata) + "\n" + lua_code) : lua_code;
190 | // OutputDebugStringA("queuing lua execution: storing lua string\n");
191 | toExecuteLuaString.store(lua_str.c_str());
192 | // OutputDebugStringA("queuing lua execution: loading lua string\n");
193 | auto res = lua_result.load();
194 | while (res == nullptr) {
195 | Sleep(10);
196 | if (std::chrono::duration_cast(
197 | std::chrono::high_resolution_clock::now() - start)
198 | .count() > 3000) {
199 | throw std::exception("Lua error: Timeout executing lua");
200 | }
201 | // // OutputDebugStringA("queuing lua execution: loading lua string in loop\n");
202 | res = lua_result.load();
203 | }
204 | // OutputDebugStringA("queuing lua execution: returning\n");
205 | return res;
206 | }
207 | throw std::exception("Lua error: Lua_State not loaded");
208 | }
--------------------------------------------------------------------------------
/X4_Rest_Reloaded/asm.asm:
--------------------------------------------------------------------------------
1 | .code
2 |
3 | extern functions:qword
4 |
5 | ; DbgHelpCreateUserDump
6 | func_120d4bcc12264f01a49264ce4e5d6600 proc
7 | jmp functions[8 * 0]
8 | func_120d4bcc12264f01a49264ce4e5d6600 endp
9 |
10 | ; DbgHelpCreateUserDumpW
11 | func_5a497ce26860415ab42f4f459876f50a proc
12 | jmp functions[8 * 1]
13 | func_5a497ce26860415ab42f4f459876f50a endp
14 |
15 | ; EnumDirTree
16 | func_09032d9487a04160b52bcd5c69d4d225 proc
17 | jmp functions[8 * 2]
18 | func_09032d9487a04160b52bcd5c69d4d225 endp
19 |
20 | ; EnumDirTreeW
21 | func_1193994b75124806925a32e2e7b3224e proc
22 | jmp functions[8 * 3]
23 | func_1193994b75124806925a32e2e7b3224e endp
24 |
25 | ; EnumerateLoadedModules
26 | func_1b8edab639384bf38c970734c669991b proc
27 | jmp functions[8 * 4]
28 | func_1b8edab639384bf38c970734c669991b endp
29 |
30 | ; EnumerateLoadedModules64
31 | func_3eeb0856fb1442d29b3827b5ff3c56ea proc
32 | jmp functions[8 * 5]
33 | func_3eeb0856fb1442d29b3827b5ff3c56ea endp
34 |
35 | ; EnumerateLoadedModulesEx
36 | func_2614d9b92afc497e96e6dc6b2c31da7a proc
37 | jmp functions[8 * 6]
38 | func_2614d9b92afc497e96e6dc6b2c31da7a endp
39 |
40 | ; EnumerateLoadedModulesExW
41 | func_41812600d28e435d8d07b04859da4f19 proc
42 | jmp functions[8 * 7]
43 | func_41812600d28e435d8d07b04859da4f19 endp
44 |
45 | ; EnumerateLoadedModulesW64
46 | func_466feb2fc7a04fe59cb6fdf1bc760e59 proc
47 | jmp functions[8 * 8]
48 | func_466feb2fc7a04fe59cb6fdf1bc760e59 endp
49 |
50 | ; ExtensionApiVersion
51 | func_7f0922f210fb4009b045ae6aeaacb605 proc
52 | jmp functions[8 * 9]
53 | func_7f0922f210fb4009b045ae6aeaacb605 endp
54 |
55 | ; FindDebugInfoFile
56 | func_f2febe9572d24fec927ba8143bcc31fc proc
57 | jmp functions[8 * 10]
58 | func_f2febe9572d24fec927ba8143bcc31fc endp
59 |
60 | ; FindDebugInfoFileEx
61 | func_af26c2bbdb894a6a9e054e83aff46558 proc
62 | jmp functions[8 * 11]
63 | func_af26c2bbdb894a6a9e054e83aff46558 endp
64 |
65 | ; FindDebugInfoFileExW
66 | func_b87a769cf3f74c039af9134860db53ef proc
67 | jmp functions[8 * 12]
68 | func_b87a769cf3f74c039af9134860db53ef endp
69 |
70 | ; FindExecutableImage
71 | func_dd8db33634954900abe53de8f2e938fb proc
72 | jmp functions[8 * 13]
73 | func_dd8db33634954900abe53de8f2e938fb endp
74 |
75 | ; FindExecutableImageEx
76 | func_e6c78f032eab43ae808e0e71b0cad112 proc
77 | jmp functions[8 * 14]
78 | func_e6c78f032eab43ae808e0e71b0cad112 endp
79 |
80 | ; FindExecutableImageExW
81 | func_89ec93494815484c989c80645c9c0d3e proc
82 | jmp functions[8 * 15]
83 | func_89ec93494815484c989c80645c9c0d3e endp
84 |
85 | ; FindFileInPath
86 | func_f7ec0ce3270949d4abd17601d65a16eb proc
87 | jmp functions[8 * 16]
88 | func_f7ec0ce3270949d4abd17601d65a16eb endp
89 |
90 | ; FindFileInSearchPath
91 | func_54ed153c41d2477f85c75c6ce7f2e8bf proc
92 | jmp functions[8 * 17]
93 | func_54ed153c41d2477f85c75c6ce7f2e8bf endp
94 |
95 | ; GetTimestampForLoadedLibrary
96 | func_628e418bc5ae47e7a634c3e2a0ba8e53 proc
97 | jmp functions[8 * 18]
98 | func_628e418bc5ae47e7a634c3e2a0ba8e53 endp
99 |
100 | ; ImageDirectoryEntryToData
101 | func_abfb253e31724ecb890696e7a302aee2 proc
102 | jmp functions[8 * 19]
103 | func_abfb253e31724ecb890696e7a302aee2 endp
104 |
105 | ; ImageDirectoryEntryToDataEx
106 | func_5014c0bbfc9243b09d7a513d0859599e proc
107 | jmp functions[8 * 20]
108 | func_5014c0bbfc9243b09d7a513d0859599e endp
109 |
110 | ; ImageNtHeader
111 | func_d7e8b7c88a074ec288e5ce183556f975 proc
112 | jmp functions[8 * 21]
113 | func_d7e8b7c88a074ec288e5ce183556f975 endp
114 |
115 | ; ImageRvaToSection
116 | func_c3814d0ad92e4cee82985eccca4cd677 proc
117 | jmp functions[8 * 22]
118 | func_c3814d0ad92e4cee82985eccca4cd677 endp
119 |
120 | ; ImageRvaToVa
121 | func_e4a98242d7664f3e9917207817fb2e39 proc
122 | jmp functions[8 * 23]
123 | func_e4a98242d7664f3e9917207817fb2e39 endp
124 |
125 | ; ImagehlpApiVersion
126 | func_5f15d681e5d248fe89737c551a5bddb9 proc
127 | jmp functions[8 * 24]
128 | func_5f15d681e5d248fe89737c551a5bddb9 endp
129 |
130 | ; ImagehlpApiVersionEx
131 | func_2e17b1f39b32459288179d47c8b777d3 proc
132 | jmp functions[8 * 25]
133 | func_2e17b1f39b32459288179d47c8b777d3 endp
134 |
135 | ; MakeSureDirectoryPathExists
136 | func_38d9a17105524d86abe70f719a7301d4 proc
137 | jmp functions[8 * 26]
138 | func_38d9a17105524d86abe70f719a7301d4 endp
139 |
140 | ; MiniDumpReadDumpStream
141 | func_3159e20812b24a879e6402ab51f56539 proc
142 | jmp functions[8 * 27]
143 | func_3159e20812b24a879e6402ab51f56539 endp
144 |
145 | ; MiniDumpWriteDump
146 | func_a7085fd75dbc48b78d3d35d2c7311377 proc
147 | jmp functions[8 * 28]
148 | func_a7085fd75dbc48b78d3d35d2c7311377 endp
149 |
150 | ; SearchTreeForFile
151 | func_5d4a8feb4fca4aae876b69106d5fc355 proc
152 | jmp functions[8 * 29]
153 | func_5d4a8feb4fca4aae876b69106d5fc355 endp
154 |
155 | ; SearchTreeForFileW
156 | func_fb3605d9102e489e834a1ba6e578bd66 proc
157 | jmp functions[8 * 30]
158 | func_fb3605d9102e489e834a1ba6e578bd66 endp
159 |
160 | ; StackWalk
161 | func_960ff22e918143ea85530407c93df6dc proc
162 | jmp functions[8 * 31]
163 | func_960ff22e918143ea85530407c93df6dc endp
164 |
165 | ; StackWalk64
166 | func_2b25ec7428e948d7885011ad1a2cb0df proc
167 | jmp functions[8 * 32]
168 | func_2b25ec7428e948d7885011ad1a2cb0df endp
169 |
170 | ; SymAddSourceStream
171 | func_0e76c185cbf1446bbed074aaa6069bf2 proc
172 | jmp functions[8 * 33]
173 | func_0e76c185cbf1446bbed074aaa6069bf2 endp
174 |
175 | ; SymAddSourceStreamA
176 | func_de254f13bd4b4138be6459d66e0cae90 proc
177 | jmp functions[8 * 34]
178 | func_de254f13bd4b4138be6459d66e0cae90 endp
179 |
180 | ; SymAddSourceStreamW
181 | func_a740cdd88dd3421a87b20c1e0076f665 proc
182 | jmp functions[8 * 35]
183 | func_a740cdd88dd3421a87b20c1e0076f665 endp
184 |
185 | ; SymAddSymbol
186 | func_8c836cc17ee14566af9e0944bfc74b06 proc
187 | jmp functions[8 * 36]
188 | func_8c836cc17ee14566af9e0944bfc74b06 endp
189 |
190 | ; SymAddSymbolW
191 | func_7f951e75a4a84e848a4c3b960e0a087d proc
192 | jmp functions[8 * 37]
193 | func_7f951e75a4a84e848a4c3b960e0a087d endp
194 |
195 | ; SymCleanup
196 | func_a86135f51fec4830afe97ef714546fda proc
197 | jmp functions[8 * 38]
198 | func_a86135f51fec4830afe97ef714546fda endp
199 |
200 | ; SymDeleteSymbol
201 | func_4b0c3a0fb8084a61a55521f0409f15eb proc
202 | jmp functions[8 * 39]
203 | func_4b0c3a0fb8084a61a55521f0409f15eb endp
204 |
205 | ; SymDeleteSymbolW
206 | func_70e5d2c0a41c4810bf8b3209d50c2eac proc
207 | jmp functions[8 * 40]
208 | func_70e5d2c0a41c4810bf8b3209d50c2eac endp
209 |
210 | ; SymEnumLines
211 | func_8d7a2ace41484fd9833988ff8e19cb25 proc
212 | jmp functions[8 * 41]
213 | func_8d7a2ace41484fd9833988ff8e19cb25 endp
214 |
215 | ; SymEnumLinesW
216 | func_f8c07b6f1c2c4f9cadd87e2fa1a148b3 proc
217 | jmp functions[8 * 42]
218 | func_f8c07b6f1c2c4f9cadd87e2fa1a148b3 endp
219 |
220 | ; SymEnumProcesses
221 | func_d4b0b901987d48b08e4ad7273d26a856 proc
222 | jmp functions[8 * 43]
223 | func_d4b0b901987d48b08e4ad7273d26a856 endp
224 |
225 | ; SymEnumSourceFileTokens
226 | func_d5799c579c5240fc8bfac1bbd9ae4649 proc
227 | jmp functions[8 * 44]
228 | func_d5799c579c5240fc8bfac1bbd9ae4649 endp
229 |
230 | ; SymEnumSourceFiles
231 | func_722ebc764f0b4aa59f3e99c7ff0f532a proc
232 | jmp functions[8 * 45]
233 | func_722ebc764f0b4aa59f3e99c7ff0f532a endp
234 |
235 | ; SymEnumSourceFilesW
236 | func_9a305c0fbb9d431694b624f2b5447fed proc
237 | jmp functions[8 * 46]
238 | func_9a305c0fbb9d431694b624f2b5447fed endp
239 |
240 | ; SymEnumSourceLines
241 | func_fdc9fbac0d994c62bc3f2f5635628cc9 proc
242 | jmp functions[8 * 47]
243 | func_fdc9fbac0d994c62bc3f2f5635628cc9 endp
244 |
245 | ; SymEnumSourceLinesW
246 | func_00e40ac92bcd4c0b9a48310cda4fa80d proc
247 | jmp functions[8 * 48]
248 | func_00e40ac92bcd4c0b9a48310cda4fa80d endp
249 |
250 | ; SymEnumSym
251 | func_646b2baef49f4de98451b729e195e025 proc
252 | jmp functions[8 * 49]
253 | func_646b2baef49f4de98451b729e195e025 endp
254 |
255 | ; SymEnumSymbols
256 | func_b0dd177ba32a4a6f86b3f7bb3f44e61c proc
257 | jmp functions[8 * 50]
258 | func_b0dd177ba32a4a6f86b3f7bb3f44e61c endp
259 |
260 | ; SymEnumSymbolsForAddr
261 | func_eb26d336a8bd4cf4b9d866d36cdebeb4 proc
262 | jmp functions[8 * 51]
263 | func_eb26d336a8bd4cf4b9d866d36cdebeb4 endp
264 |
265 | ; SymEnumSymbolsForAddrW
266 | func_9f051ed805b44911825043937af76a03 proc
267 | jmp functions[8 * 52]
268 | func_9f051ed805b44911825043937af76a03 endp
269 |
270 | ; SymEnumSymbolsW
271 | func_8cbcc99a34664cc781a340f9c037c8c7 proc
272 | jmp functions[8 * 53]
273 | func_8cbcc99a34664cc781a340f9c037c8c7 endp
274 |
275 | ; SymEnumTypes
276 | func_145aadd283804790a87a37f9d2cba57c proc
277 | jmp functions[8 * 54]
278 | func_145aadd283804790a87a37f9d2cba57c endp
279 |
280 | ; SymEnumTypesByName
281 | func_aa0f7b045a4f463cb67e254f91549a09 proc
282 | jmp functions[8 * 55]
283 | func_aa0f7b045a4f463cb67e254f91549a09 endp
284 |
285 | ; SymEnumTypesByNameW
286 | func_d6cc2c83f3f94b65a97bcc36f1118e3a proc
287 | jmp functions[8 * 56]
288 | func_d6cc2c83f3f94b65a97bcc36f1118e3a endp
289 |
290 | ; SymEnumTypesW
291 | func_8207fe8372bf4fd29147728f7e4f96f5 proc
292 | jmp functions[8 * 57]
293 | func_8207fe8372bf4fd29147728f7e4f96f5 endp
294 |
295 | ; SymEnumerateModules
296 | func_c4c876a265e142e4a5d9cf1de138c9e1 proc
297 | jmp functions[8 * 58]
298 | func_c4c876a265e142e4a5d9cf1de138c9e1 endp
299 |
300 | ; SymEnumerateModules64
301 | func_98e192b898014789bc6f1c05681c907c proc
302 | jmp functions[8 * 59]
303 | func_98e192b898014789bc6f1c05681c907c endp
304 |
305 | ; SymEnumerateModulesW64
306 | func_40a3487452b24844a11862d6e43d7ac9 proc
307 | jmp functions[8 * 60]
308 | func_40a3487452b24844a11862d6e43d7ac9 endp
309 |
310 | ; SymEnumerateSymbols
311 | func_455f30bb765b4d47a0fc33997a41e82c proc
312 | jmp functions[8 * 61]
313 | func_455f30bb765b4d47a0fc33997a41e82c endp
314 |
315 | ; SymEnumerateSymbols64
316 | func_aae6ef28a2d24cbd881939afb65ae9f1 proc
317 | jmp functions[8 * 62]
318 | func_aae6ef28a2d24cbd881939afb65ae9f1 endp
319 |
320 | ; SymEnumerateSymbolsW
321 | func_791b356f9bb64636b73854d75eb95b70 proc
322 | jmp functions[8 * 63]
323 | func_791b356f9bb64636b73854d75eb95b70 endp
324 |
325 | ; SymEnumerateSymbolsW64
326 | func_a827e2f1f7a5433e91cf06febbc8edad proc
327 | jmp functions[8 * 64]
328 | func_a827e2f1f7a5433e91cf06febbc8edad endp
329 |
330 | ; SymFindDebugInfoFile
331 | func_3d0575058c3b4ad588fa5cc31f3aec04 proc
332 | jmp functions[8 * 65]
333 | func_3d0575058c3b4ad588fa5cc31f3aec04 endp
334 |
335 | ; SymFindDebugInfoFileW
336 | func_448e0c3500eb42e993a4028cefa01302 proc
337 | jmp functions[8 * 66]
338 | func_448e0c3500eb42e993a4028cefa01302 endp
339 |
340 | ; SymFindExecutableImage
341 | func_9905fb79efb246afafa67d36de3f46d8 proc
342 | jmp functions[8 * 67]
343 | func_9905fb79efb246afafa67d36de3f46d8 endp
344 |
345 | ; SymFindExecutableImageW
346 | func_0472d45552d34d308b36ca2202222f15 proc
347 | jmp functions[8 * 68]
348 | func_0472d45552d34d308b36ca2202222f15 endp
349 |
350 | ; SymFindFileInPath
351 | func_6398187f61b84534a2385053efe8950c proc
352 | jmp functions[8 * 69]
353 | func_6398187f61b84534a2385053efe8950c endp
354 |
355 | ; SymFindFileInPathW
356 | func_23043282d8c64216951295c880cb7da0 proc
357 | jmp functions[8 * 70]
358 | func_23043282d8c64216951295c880cb7da0 endp
359 |
360 | ; SymFromAddr
361 | func_52ce42d41d404aa0b5235efdbbb6e817 proc
362 | jmp functions[8 * 71]
363 | func_52ce42d41d404aa0b5235efdbbb6e817 endp
364 |
365 | ; SymFromAddrW
366 | func_a6731ba4b38f41dea6ddf2b52e84dcb9 proc
367 | jmp functions[8 * 72]
368 | func_a6731ba4b38f41dea6ddf2b52e84dcb9 endp
369 |
370 | ; SymFromIndex
371 | func_687d171a3b8c4602874f8b3f5cc673e3 proc
372 | jmp functions[8 * 73]
373 | func_687d171a3b8c4602874f8b3f5cc673e3 endp
374 |
375 | ; SymFromIndexW
376 | func_2df01a5a2266489e848d4409f98de010 proc
377 | jmp functions[8 * 74]
378 | func_2df01a5a2266489e848d4409f98de010 endp
379 |
380 | ; SymFromName
381 | func_1104eaf18fe04128a03ed34750bc534b proc
382 | jmp functions[8 * 75]
383 | func_1104eaf18fe04128a03ed34750bc534b endp
384 |
385 | ; SymFromNameW
386 | func_4f88921bb09945138322a73b780fa936 proc
387 | jmp functions[8 * 76]
388 | func_4f88921bb09945138322a73b780fa936 endp
389 |
390 | ; SymFromToken
391 | func_a6963f71dad0411195cdc60bf12a58b6 proc
392 | jmp functions[8 * 77]
393 | func_a6963f71dad0411195cdc60bf12a58b6 endp
394 |
395 | ; SymFromTokenW
396 | func_2e2ac702406a40359779ee92f3124df9 proc
397 | jmp functions[8 * 78]
398 | func_2e2ac702406a40359779ee92f3124df9 endp
399 |
400 | ; SymFunctionTableAccess
401 | func_525c710710b74849985e248e90a6b7a9 proc
402 | jmp functions[8 * 79]
403 | func_525c710710b74849985e248e90a6b7a9 endp
404 |
405 | ; SymFunctionTableAccess64
406 | func_f8432a5bde234aa7b091a0190692821e proc
407 | jmp functions[8 * 80]
408 | func_f8432a5bde234aa7b091a0190692821e endp
409 |
410 | ; SymGetFileLineOffsets64
411 | func_5ce186fe326348c080e04634555c4c40 proc
412 | jmp functions[8 * 81]
413 | func_5ce186fe326348c080e04634555c4c40 endp
414 |
415 | ; SymGetHomeDirectory
416 | func_b7bf49f769dd4f188626ea3e93ed228d proc
417 | jmp functions[8 * 82]
418 | func_b7bf49f769dd4f188626ea3e93ed228d endp
419 |
420 | ; SymGetHomeDirectoryW
421 | func_d61208f4506149ee99fe708cfc50276d proc
422 | jmp functions[8 * 83]
423 | func_d61208f4506149ee99fe708cfc50276d endp
424 |
425 | ; SymGetLineFromAddr
426 | func_cea06f13c17e4640bf33aff62e1d237c proc
427 | jmp functions[8 * 84]
428 | func_cea06f13c17e4640bf33aff62e1d237c endp
429 |
430 | ; SymGetLineFromAddr64
431 | func_1e68542de6274511b826c3f25de44fed proc
432 | jmp functions[8 * 85]
433 | func_1e68542de6274511b826c3f25de44fed endp
434 |
435 | ; SymGetLineFromAddrW64
436 | func_2ce9dc8f6a394be9b7d4e883e5c90be3 proc
437 | jmp functions[8 * 86]
438 | func_2ce9dc8f6a394be9b7d4e883e5c90be3 endp
439 |
440 | ; SymGetLineFromName
441 | func_78644265a3cd46f4aa7dfdae1b5a47f7 proc
442 | jmp functions[8 * 87]
443 | func_78644265a3cd46f4aa7dfdae1b5a47f7 endp
444 |
445 | ; SymGetLineFromName64
446 | func_5a94a69a463e4fd6ad748a5ca5b7e768 proc
447 | jmp functions[8 * 88]
448 | func_5a94a69a463e4fd6ad748a5ca5b7e768 endp
449 |
450 | ; SymGetLineFromNameW64
451 | func_0a8d3143fbc149888df42da24aea9d41 proc
452 | jmp functions[8 * 89]
453 | func_0a8d3143fbc149888df42da24aea9d41 endp
454 |
455 | ; SymGetLineNext
456 | func_066cce76939044c4832e64bc7386a7c7 proc
457 | jmp functions[8 * 90]
458 | func_066cce76939044c4832e64bc7386a7c7 endp
459 |
460 | ; SymGetLineNext64
461 | func_0bc368d8d7984aaa852faa7f3dcf8b63 proc
462 | jmp functions[8 * 91]
463 | func_0bc368d8d7984aaa852faa7f3dcf8b63 endp
464 |
465 | ; SymGetLineNextW64
466 | func_cea60d6bd942402599685d84c4fc7bb6 proc
467 | jmp functions[8 * 92]
468 | func_cea60d6bd942402599685d84c4fc7bb6 endp
469 |
470 | ; SymGetLinePrev
471 | func_c6715e6b39e04b0e96364e368b56bc67 proc
472 | jmp functions[8 * 93]
473 | func_c6715e6b39e04b0e96364e368b56bc67 endp
474 |
475 | ; SymGetLinePrev64
476 | func_3d37ff9b3a574909a3766f920622532e proc
477 | jmp functions[8 * 94]
478 | func_3d37ff9b3a574909a3766f920622532e endp
479 |
480 | ; SymGetLinePrevW64
481 | func_0817f91aa11c478abd68a9e87ded2109 proc
482 | jmp functions[8 * 95]
483 | func_0817f91aa11c478abd68a9e87ded2109 endp
484 |
485 | ; SymGetModuleBase
486 | func_1a0d0baacecf46bea01f2fc4b39e2ab8 proc
487 | jmp functions[8 * 96]
488 | func_1a0d0baacecf46bea01f2fc4b39e2ab8 endp
489 |
490 | ; SymGetModuleBase64
491 | func_1d7b98493ef54968bf8098a58c778205 proc
492 | jmp functions[8 * 97]
493 | func_1d7b98493ef54968bf8098a58c778205 endp
494 |
495 | ; SymGetModuleInfo
496 | func_683519a66d6c4e3fab94abf5a5cdfb1e proc
497 | jmp functions[8 * 98]
498 | func_683519a66d6c4e3fab94abf5a5cdfb1e endp
499 |
500 | ; SymGetModuleInfo64
501 | func_40cb2c5223504d0cacc7f445b191a07c proc
502 | jmp functions[8 * 99]
503 | func_40cb2c5223504d0cacc7f445b191a07c endp
504 |
505 | ; SymGetModuleInfoW
506 | func_fced6dea3d6d4eeab466e36dd9c601dd proc
507 | jmp functions[8 * 100]
508 | func_fced6dea3d6d4eeab466e36dd9c601dd endp
509 |
510 | ; SymGetModuleInfoW64
511 | func_57c9111d75b04a22a4419cc2f3ee42e1 proc
512 | jmp functions[8 * 101]
513 | func_57c9111d75b04a22a4419cc2f3ee42e1 endp
514 |
515 | ; SymGetOmapBlockBase
516 | func_c184d00e42c546ecbdf28a73c3d0860c proc
517 | jmp functions[8 * 102]
518 | func_c184d00e42c546ecbdf28a73c3d0860c endp
519 |
520 | ; SymGetOmaps
521 | func_edcfca8dcb4143a4b5939aa44c911529 proc
522 | jmp functions[8 * 103]
523 | func_edcfca8dcb4143a4b5939aa44c911529 endp
524 |
525 | ; SymGetOptions
526 | func_3b37a9a5169c4fc189570cf39cda7e8a proc
527 | jmp functions[8 * 104]
528 | func_3b37a9a5169c4fc189570cf39cda7e8a endp
529 |
530 | ; SymGetScope
531 | func_2ad339d96ee84a8cbd396a60a1777c11 proc
532 | jmp functions[8 * 105]
533 | func_2ad339d96ee84a8cbd396a60a1777c11 endp
534 |
535 | ; SymGetScopeW
536 | func_894e37c16a2647d28212b6703d8878f7 proc
537 | jmp functions[8 * 106]
538 | func_894e37c16a2647d28212b6703d8878f7 endp
539 |
540 | ; SymGetSearchPath
541 | func_2dbf49fa4ae24e6a809d1b2b16dba0e2 proc
542 | jmp functions[8 * 107]
543 | func_2dbf49fa4ae24e6a809d1b2b16dba0e2 endp
544 |
545 | ; SymGetSearchPathW
546 | func_e9400fca96b8475281335e6c372c0b24 proc
547 | jmp functions[8 * 108]
548 | func_e9400fca96b8475281335e6c372c0b24 endp
549 |
550 | ; SymGetSourceFile
551 | func_d2f648a8edad4f1a9ebe2a68fcbbc483 proc
552 | jmp functions[8 * 109]
553 | func_d2f648a8edad4f1a9ebe2a68fcbbc483 endp
554 |
555 | ; SymGetSourceFileFromToken
556 | func_620bde3040d44c599eed447e352225f8 proc
557 | jmp functions[8 * 110]
558 | func_620bde3040d44c599eed447e352225f8 endp
559 |
560 | ; SymGetSourceFileFromTokenW
561 | func_1905cc6d08f641ec975cef2911d458af proc
562 | jmp functions[8 * 111]
563 | func_1905cc6d08f641ec975cef2911d458af endp
564 |
565 | ; SymGetSourceFileToken
566 | func_fcf8508608f145a28f0181d9b2d29924 proc
567 | jmp functions[8 * 112]
568 | func_fcf8508608f145a28f0181d9b2d29924 endp
569 |
570 | ; SymGetSourceFileTokenW
571 | func_471b532f8e4742acb3159c237694d824 proc
572 | jmp functions[8 * 113]
573 | func_471b532f8e4742acb3159c237694d824 endp
574 |
575 | ; SymGetSourceFileW
576 | func_9a8ecc62ddc64d278c8c6f9428d9aa83 proc
577 | jmp functions[8 * 114]
578 | func_9a8ecc62ddc64d278c8c6f9428d9aa83 endp
579 |
580 | ; SymGetSourceVarFromToken
581 | func_b465689dea434304b4115a98213e622b proc
582 | jmp functions[8 * 115]
583 | func_b465689dea434304b4115a98213e622b endp
584 |
585 | ; SymGetSourceVarFromTokenW
586 | func_2489d534a2f0417a92217160ced2cef0 proc
587 | jmp functions[8 * 116]
588 | func_2489d534a2f0417a92217160ced2cef0 endp
589 |
590 | ; SymGetSymFromAddr
591 | func_32f4d89c30ba4f5a87e3ac4837523bd4 proc
592 | jmp functions[8 * 117]
593 | func_32f4d89c30ba4f5a87e3ac4837523bd4 endp
594 |
595 | ; SymGetSymFromAddr64
596 | func_b55eb589335f4ba4ae78b74cdcfa0390 proc
597 | jmp functions[8 * 118]
598 | func_b55eb589335f4ba4ae78b74cdcfa0390 endp
599 |
600 | ; SymGetSymFromName
601 | func_5bfa3f0cd59640afbf9809ac04fdf739 proc
602 | jmp functions[8 * 119]
603 | func_5bfa3f0cd59640afbf9809ac04fdf739 endp
604 |
605 | ; SymGetSymFromName64
606 | func_782776b4332941778dd354455ab2d6cf proc
607 | jmp functions[8 * 120]
608 | func_782776b4332941778dd354455ab2d6cf endp
609 |
610 | ; SymGetSymNext
611 | func_0c91f5d0767d4ed89ad8d47a9267a29f proc
612 | jmp functions[8 * 121]
613 | func_0c91f5d0767d4ed89ad8d47a9267a29f endp
614 |
615 | ; SymGetSymNext64
616 | func_d2600d742c684a13a7789e5fba421ef2 proc
617 | jmp functions[8 * 122]
618 | func_d2600d742c684a13a7789e5fba421ef2 endp
619 |
620 | ; SymGetSymPrev
621 | func_182399f1efaa448198a6b22edaa9a48a proc
622 | jmp functions[8 * 123]
623 | func_182399f1efaa448198a6b22edaa9a48a endp
624 |
625 | ; SymGetSymPrev64
626 | func_570ef0385bd64edd8c4276b9216deb5b proc
627 | jmp functions[8 * 124]
628 | func_570ef0385bd64edd8c4276b9216deb5b endp
629 |
630 | ; SymGetSymbolFile
631 | func_fcacc47e5035486aa15a0496049d8cd0 proc
632 | jmp functions[8 * 125]
633 | func_fcacc47e5035486aa15a0496049d8cd0 endp
634 |
635 | ; SymGetSymbolFileW
636 | func_1a44d0aaab1b4e6d9c83e8517f223c7a proc
637 | jmp functions[8 * 126]
638 | func_1a44d0aaab1b4e6d9c83e8517f223c7a endp
639 |
640 | ; SymGetTypeFromName
641 | func_ce687ef4e98546e0972a5077f9ee574a proc
642 | jmp functions[8 * 127]
643 | func_ce687ef4e98546e0972a5077f9ee574a endp
644 |
645 | ; SymGetTypeFromNameW
646 | func_6fc85559dcea47779831cfec37c60c79 proc
647 | jmp functions[8 * 128]
648 | func_6fc85559dcea47779831cfec37c60c79 endp
649 |
650 | ; SymGetTypeInfo
651 | func_81b2a3adb3e145e7904566c0a9a26674 proc
652 | jmp functions[8 * 129]
653 | func_81b2a3adb3e145e7904566c0a9a26674 endp
654 |
655 | ; SymGetTypeInfoEx
656 | func_8e2b4a7c44db45f19b209f6abe5c583a proc
657 | jmp functions[8 * 130]
658 | func_8e2b4a7c44db45f19b209f6abe5c583a endp
659 |
660 | ; SymGetUnwindInfo
661 | func_865275462e5f4ea893ddd2511003590a proc
662 | jmp functions[8 * 131]
663 | func_865275462e5f4ea893ddd2511003590a endp
664 |
665 | ; SymInitialize
666 | func_d3a0b69f5985412ab83e7be62def9100 proc
667 | jmp functions[8 * 132]
668 | func_d3a0b69f5985412ab83e7be62def9100 endp
669 |
670 | ; SymInitializeW
671 | func_193068edf91e47abada775d2a6d20fb4 proc
672 | jmp functions[8 * 133]
673 | func_193068edf91e47abada775d2a6d20fb4 endp
674 |
675 | ; SymLoadModule
676 | func_e0978ce2ae91486d9bb1012066224f84 proc
677 | jmp functions[8 * 134]
678 | func_e0978ce2ae91486d9bb1012066224f84 endp
679 |
680 | ; SymLoadModule64
681 | func_abbd939191f04bfdbd558016481be009 proc
682 | jmp functions[8 * 135]
683 | func_abbd939191f04bfdbd558016481be009 endp
684 |
685 | ; SymLoadModuleEx
686 | func_bd69cbfeaf77402d8384c33292dab4c4 proc
687 | jmp functions[8 * 136]
688 | func_bd69cbfeaf77402d8384c33292dab4c4 endp
689 |
690 | ; SymLoadModuleExW
691 | func_197fe9c27e85468a902d00595b4c88e8 proc
692 | jmp functions[8 * 137]
693 | func_197fe9c27e85468a902d00595b4c88e8 endp
694 |
695 | ; SymMatchFileName
696 | func_0224b297621a45bbaf81d37926ae7843 proc
697 | jmp functions[8 * 138]
698 | func_0224b297621a45bbaf81d37926ae7843 endp
699 |
700 | ; SymMatchFileNameW
701 | func_6d4997e986d347c99db25cc24fd89769 proc
702 | jmp functions[8 * 139]
703 | func_6d4997e986d347c99db25cc24fd89769 endp
704 |
705 | ; SymMatchString
706 | func_8c5817cae33a46c4bd74b608d469a288 proc
707 | jmp functions[8 * 140]
708 | func_8c5817cae33a46c4bd74b608d469a288 endp
709 |
710 | ; SymMatchStringA
711 | func_3e9148a80a964577ae2aaac1c94b2903 proc
712 | jmp functions[8 * 141]
713 | func_3e9148a80a964577ae2aaac1c94b2903 endp
714 |
715 | ; SymMatchStringW
716 | func_44a1ecb7444a48d084415826ab4b74a6 proc
717 | jmp functions[8 * 142]
718 | func_44a1ecb7444a48d084415826ab4b74a6 endp
719 |
720 | ; SymNext
721 | func_3786b412b7424191a8f92863a2995210 proc
722 | jmp functions[8 * 143]
723 | func_3786b412b7424191a8f92863a2995210 endp
724 |
725 | ; SymNextW
726 | func_324bf5f45ffd47798af156cc14e54be0 proc
727 | jmp functions[8 * 144]
728 | func_324bf5f45ffd47798af156cc14e54be0 endp
729 |
730 | ; SymPrev
731 | func_c13e1510288842af89f4e496146e1bf7 proc
732 | jmp functions[8 * 145]
733 | func_c13e1510288842af89f4e496146e1bf7 endp
734 |
735 | ; SymPrevW
736 | func_88bbd0071d354028b3369a50a85ca00a proc
737 | jmp functions[8 * 146]
738 | func_88bbd0071d354028b3369a50a85ca00a endp
739 |
740 | ; SymRefreshModuleList
741 | func_804a2084a6b4424ba28e1eb11b5f8033 proc
742 | jmp functions[8 * 147]
743 | func_804a2084a6b4424ba28e1eb11b5f8033 endp
744 |
745 | ; SymRegisterCallback
746 | func_ab01306cad744492a985ce3b95b5960c proc
747 | jmp functions[8 * 148]
748 | func_ab01306cad744492a985ce3b95b5960c endp
749 |
750 | ; SymRegisterCallback64
751 | func_8080c183e2b046bc86678755f34eb924 proc
752 | jmp functions[8 * 149]
753 | func_8080c183e2b046bc86678755f34eb924 endp
754 |
755 | ; SymRegisterCallbackW64
756 | func_c5fc4017fa724f14952456e291337c19 proc
757 | jmp functions[8 * 150]
758 | func_c5fc4017fa724f14952456e291337c19 endp
759 |
760 | ; SymRegisterFunctionEntryCallback
761 | func_57ac55e2fdd84ec99bd1cf697b38724a proc
762 | jmp functions[8 * 151]
763 | func_57ac55e2fdd84ec99bd1cf697b38724a endp
764 |
765 | ; SymRegisterFunctionEntryCallback64
766 | func_4d7f6fcf84134956b99ca85165e3eda7 proc
767 | jmp functions[8 * 152]
768 | func_4d7f6fcf84134956b99ca85165e3eda7 endp
769 |
770 | ; SymSearch
771 | func_b581abf14f2b44d4a4aa6508dc7c98aa proc
772 | jmp functions[8 * 153]
773 | func_b581abf14f2b44d4a4aa6508dc7c98aa endp
774 |
775 | ; SymSearchW
776 | func_dae8a0938d6a4ea28ee27c8ad296fb68 proc
777 | jmp functions[8 * 154]
778 | func_dae8a0938d6a4ea28ee27c8ad296fb68 endp
779 |
780 | ; SymSetContext
781 | func_0dd96a1b03594209bcecc77fa4d3ae77 proc
782 | jmp functions[8 * 155]
783 | func_0dd96a1b03594209bcecc77fa4d3ae77 endp
784 |
785 | ; SymSetHomeDirectory
786 | func_746274b5a3e24932ab15ddf6497f6975 proc
787 | jmp functions[8 * 156]
788 | func_746274b5a3e24932ab15ddf6497f6975 endp
789 |
790 | ; SymSetHomeDirectoryW
791 | func_141be2aa490d4155ab9bcb065ad25496 proc
792 | jmp functions[8 * 157]
793 | func_141be2aa490d4155ab9bcb065ad25496 endp
794 |
795 | ; SymSetOptions
796 | func_bb8e0848bb654cbaaf585dce364b82c7 proc
797 | jmp functions[8 * 158]
798 | func_bb8e0848bb654cbaaf585dce364b82c7 endp
799 |
800 | ; SymSetParentWindow
801 | func_087e38567ed94e3c922b95f90f297d28 proc
802 | jmp functions[8 * 159]
803 | func_087e38567ed94e3c922b95f90f297d28 endp
804 |
805 | ; SymSetScopeFromAddr
806 | func_cfbb7c03c7ab440588c2460829842e68 proc
807 | jmp functions[8 * 160]
808 | func_cfbb7c03c7ab440588c2460829842e68 endp
809 |
810 | ; SymSetScopeFromIndex
811 | func_f0fe26bbce8843429df3f4dfd62abd0f proc
812 | jmp functions[8 * 161]
813 | func_f0fe26bbce8843429df3f4dfd62abd0f endp
814 |
815 | ; SymSetSearchPath
816 | func_e83f581931b342ccb0257e576fe9472f proc
817 | jmp functions[8 * 162]
818 | func_e83f581931b342ccb0257e576fe9472f endp
819 |
820 | ; SymSetSearchPathW
821 | func_23101f60bfbc43eabb4bd00f1f8fd433 proc
822 | jmp functions[8 * 163]
823 | func_23101f60bfbc43eabb4bd00f1f8fd433 endp
824 |
825 | ; SymSrvDeltaName
826 | func_0e8629d277e148dabe58195bbd1bc19f proc
827 | jmp functions[8 * 164]
828 | func_0e8629d277e148dabe58195bbd1bc19f endp
829 |
830 | ; SymSrvDeltaNameW
831 | func_32c75c9ffff64c8c96ef07dbdec9876a proc
832 | jmp functions[8 * 165]
833 | func_32c75c9ffff64c8c96ef07dbdec9876a endp
834 |
835 | ; SymSrvGetFileIndexInfo
836 | func_a20c633cb6c74cda86290059e5346038 proc
837 | jmp functions[8 * 166]
838 | func_a20c633cb6c74cda86290059e5346038 endp
839 |
840 | ; SymSrvGetFileIndexInfoW
841 | func_44e8bb14d6864d2daf68692969e5bb7f proc
842 | jmp functions[8 * 167]
843 | func_44e8bb14d6864d2daf68692969e5bb7f endp
844 |
845 | ; SymSrvGetFileIndexString
846 | func_a4be3fb2023a493da75af93dff4d760c proc
847 | jmp functions[8 * 168]
848 | func_a4be3fb2023a493da75af93dff4d760c endp
849 |
850 | ; SymSrvGetFileIndexStringW
851 | func_9c5b914d48b743e0b6bd5353ee3a4399 proc
852 | jmp functions[8 * 169]
853 | func_9c5b914d48b743e0b6bd5353ee3a4399 endp
854 |
855 | ; SymSrvGetFileIndexes
856 | func_bb3dd46db1f049f1a99916716dbbf7c7 proc
857 | jmp functions[8 * 170]
858 | func_bb3dd46db1f049f1a99916716dbbf7c7 endp
859 |
860 | ; SymSrvGetFileIndexesW
861 | func_27cfbca0d08744ebb198e1eae6ec3918 proc
862 | jmp functions[8 * 171]
863 | func_27cfbca0d08744ebb198e1eae6ec3918 endp
864 |
865 | ; SymSrvGetSupplement
866 | func_60dabb1b3bcb43ae8e3b391bd6d3bb34 proc
867 | jmp functions[8 * 172]
868 | func_60dabb1b3bcb43ae8e3b391bd6d3bb34 endp
869 |
870 | ; SymSrvGetSupplementW
871 | func_55bd03b68b534f73af20c7fefa915edb proc
872 | jmp functions[8 * 173]
873 | func_55bd03b68b534f73af20c7fefa915edb endp
874 |
875 | ; SymSrvIsStore
876 | func_cff3efe196564457b8e3f54aa638bab7 proc
877 | jmp functions[8 * 174]
878 | func_cff3efe196564457b8e3f54aa638bab7 endp
879 |
880 | ; SymSrvIsStoreW
881 | func_895935ec7e1c4ff5bf9f4fc86be58086 proc
882 | jmp functions[8 * 175]
883 | func_895935ec7e1c4ff5bf9f4fc86be58086 endp
884 |
885 | ; SymSrvStoreFile
886 | func_462730cd24b54245b63efec1fa66356f proc
887 | jmp functions[8 * 176]
888 | func_462730cd24b54245b63efec1fa66356f endp
889 |
890 | ; SymSrvStoreFileW
891 | func_d890c2adf05647bfa3827591729ee96f proc
892 | jmp functions[8 * 177]
893 | func_d890c2adf05647bfa3827591729ee96f endp
894 |
895 | ; SymSrvStoreSupplement
896 | func_7b912c74bcc147fd92431bbf91b73b72 proc
897 | jmp functions[8 * 178]
898 | func_7b912c74bcc147fd92431bbf91b73b72 endp
899 |
900 | ; SymSrvStoreSupplementW
901 | func_4cba7942d15643fcb3568cdbb62f0b49 proc
902 | jmp functions[8 * 179]
903 | func_4cba7942d15643fcb3568cdbb62f0b49 endp
904 |
905 | ; SymUnDName
906 | func_9a4296e0d01e4a9aad23c9e0185af0eb proc
907 | jmp functions[8 * 180]
908 | func_9a4296e0d01e4a9aad23c9e0185af0eb endp
909 |
910 | ; SymUnDName64
911 | func_af3ae5b04ef147a593eb175607b36644 proc
912 | jmp functions[8 * 181]
913 | func_af3ae5b04ef147a593eb175607b36644 endp
914 |
915 | ; SymUnloadModule
916 | func_8f5c3fcc90cb4b58a81de4668d9fedd7 proc
917 | jmp functions[8 * 182]
918 | func_8f5c3fcc90cb4b58a81de4668d9fedd7 endp
919 |
920 | ; SymUnloadModule64
921 | func_3e41f8550d484736afdcb72ab71d582a proc
922 | jmp functions[8 * 183]
923 | func_3e41f8550d484736afdcb72ab71d582a endp
924 |
925 | ; UnDecorateSymbolName
926 | func_ca821d1ff479496baa8acd471c1f45e1 proc
927 | jmp functions[8 * 184]
928 | func_ca821d1ff479496baa8acd471c1f45e1 endp
929 |
930 | ; UnDecorateSymbolNameW
931 | func_22c30795f97942f087a3ca9298bee45b proc
932 | jmp functions[8 * 185]
933 | func_22c30795f97942f087a3ca9298bee45b endp
934 |
935 | ; WinDbgExtensionDllInit
936 | func_79fe5515ae5a48af86f86890db997bf1 proc
937 | jmp functions[8 * 186]
938 | func_79fe5515ae5a48af86f86890db997bf1 endp
939 |
940 | ; block
941 | func_7ca12b5790a14cce8af7944e21f1688f proc
942 | jmp functions[8 * 187]
943 | func_7ca12b5790a14cce8af7944e21f1688f endp
944 |
945 | ; chksym
946 | func_9d545dab16b1421db68cffa667efde1a proc
947 | jmp functions[8 * 188]
948 | func_9d545dab16b1421db68cffa667efde1a endp
949 |
950 | ; dbghelp
951 | func_070ff7d20e70427fb616aa15c13571a7 proc
952 | jmp functions[8 * 189]
953 | func_070ff7d20e70427fb616aa15c13571a7 endp
954 |
955 | ; dh
956 | func_24bb3967fb26495e974456a6b59ac868 proc
957 | jmp functions[8 * 190]
958 | func_24bb3967fb26495e974456a6b59ac868 endp
959 |
960 | ; fptr
961 | func_3406ed7f7009480ca043f8806021f6c6 proc
962 | jmp functions[8 * 191]
963 | func_3406ed7f7009480ca043f8806021f6c6 endp
964 |
965 | ; homedir
966 | func_9335553cbd614af3b477fd47a1372298 proc
967 | jmp functions[8 * 192]
968 | func_9335553cbd614af3b477fd47a1372298 endp
969 |
970 | ; itoldyouso
971 | func_4c3d834e7aab488ea7d9945e86414bfa proc
972 | jmp functions[8 * 193]
973 | func_4c3d834e7aab488ea7d9945e86414bfa endp
974 |
975 | ; lmi
976 | func_8d7adb0635444a13858d8967c6dd5ab5 proc
977 | jmp functions[8 * 194]
978 | func_8d7adb0635444a13858d8967c6dd5ab5 endp
979 |
980 | ; lminfo
981 | func_643aecf52a8d42fcb9cf3ffbc23954fa proc
982 | jmp functions[8 * 195]
983 | func_643aecf52a8d42fcb9cf3ffbc23954fa endp
984 |
985 | ; omap
986 | func_8dabd3f071664e649778eb9d05b61428 proc
987 | jmp functions[8 * 196]
988 | func_8dabd3f071664e649778eb9d05b61428 endp
989 |
990 | ; srcfiles
991 | func_b42d4406f4fd4838947cfe653151e902 proc
992 | jmp functions[8 * 197]
993 | func_b42d4406f4fd4838947cfe653151e902 endp
994 |
995 | ; stack_force_ebp
996 | func_74c2088e998743b486c6d77a75ee2003 proc
997 | jmp functions[8 * 198]
998 | func_74c2088e998743b486c6d77a75ee2003 endp
999 |
1000 | ; stackdbg
1001 | func_74d50ac6eca9436abb23b5517b357927 proc
1002 | jmp functions[8 * 199]
1003 | func_74d50ac6eca9436abb23b5517b357927 endp
1004 |
1005 | ; sym
1006 | func_407c72207a33454e9c1ce97ac6dd17b9 proc
1007 | jmp functions[8 * 200]
1008 | func_407c72207a33454e9c1ce97ac6dd17b9 endp
1009 |
1010 | ; symsrv
1011 | func_35f4c1a08d814ace98c166478f431e73 proc
1012 | jmp functions[8 * 201]
1013 | func_35f4c1a08d814ace98c166478f431e73 endp
1014 |
1015 | ; vc7fpo
1016 | func_6ac821f951f445aea5abfee4d1136db4 proc
1017 | jmp functions[8 * 202]
1018 | func_6ac821f951f445aea5abfee4d1136db4 endp
1019 |
1020 |
1021 | end
1022 |
--------------------------------------------------------------------------------
/X4_Rest_Reloaded/endpoint_impl/common_funcs.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2021-2023 Peter Repukat - FlatspotSoftware
3 |
4 | Use of this source code is governed by the MIT
5 | license that can be found in the LICENSE file or at
6 | https://opensource.org/licenses/MIT.
7 | */
8 |
9 | #pragma once
10 |
11 | #include "../httpserver/HttpServer.h"
12 | #include "../ffi/FFIInvoke.h"
13 |
14 | #include "../_lua_.h"
15 | #include "../lua_scripts/dump_lua.h"
16 |
17 |
18 |
19 | inline void RegisterCommonFunctions(INIT_PARAMS()) {
20 | HttpServer::AddEndpoint(SIMPLE_GET_HANDLER(GetGameStartName));
21 | // gametime doesn't work from separate thread; use lua in render-thread as workaround
22 | // HttpServer::AddEndpoint(SIMPLE_GET_HANDLER(GetCurrentGameTime));
23 | HttpServer::AddEndpoint({"/GetCurrentGameTime", HttpServer::Method::GET,
24 | [ & ](const httplib::Request& req, httplib::Response& res) {
25 | if (ui_lua_state != nullptr) {
26 |
27 | const auto lua_script =R"(
28 | local ffi = require("ffi")
29 | local C = ffi.C
30 | ffi.cdef[[
31 | double GetCurrentGameTime(void);
32 | ]]
33 | return C.GetCurrentGameTime()
34 | )";
35 |
36 | const auto result = executeLua(lua_script, true, false);
37 |
38 | res.set_content(result, "application/json");
39 | return;
40 | }
41 | SET_CONTENT(({false}));
42 | }});
43 |
44 | HttpServer::AddEndpoint(SIMPLE_GET_HANDLER(GetCurrentUTCDataTime));
45 |
46 | HttpServer::AddEndpoint({"/Pause", HttpServer::Method::POST,
47 | [ & ](const httplib::Request& req, httplib::Response& res) {
48 | if (ui_lua_state != nullptr) {
49 | const auto result = executeLua("Pause()", false);
50 | SET_CONTENT(({true}));
51 | return;
52 | }
53 | SET_CONTENT(({false}));
54 | },
55 | {"[boolean]"}});
56 |
57 | HttpServer::AddEndpoint({"/Unpause", HttpServer::Method::POST,
58 | [ & ](const httplib::Request& req, httplib::Response& res) {
59 | if (ui_lua_state != nullptr) {
60 | const auto result = executeLua("Unpause()", false);
61 | SET_CONTENT(({true}));
62 | return;
63 | }
64 | SET_CONTENT(({false}));
65 | },
66 | {"[boolean]"}});
67 |
68 |
69 | HttpServer::AddEndpoint({"/DumpLua", HttpServer::Method::GET,
70 | [ & ](const httplib::Request& req, httplib::Response& res) {
71 | if (ui_lua_state != nullptr) {
72 |
73 | const auto result = executeLua(dump_lua, true, false);
74 |
75 | res.set_content(result, "application/json");
76 | return;
77 | }
78 | SET_CONTENT(({false}));
79 | },
80 | "JSON", "experimental; don't rely on it"});
81 |
82 | #ifdef _DEBUG
83 | HttpServer::AddEndpoint({"/ExecuteLuaScript", HttpServer::Method::POST,
84 | [ & ](const httplib::Request& req, httplib::Response& res) {
85 | if (ui_lua_state != nullptr) {
86 |
87 | const auto result = executeLua(req.body, false, false);
88 |
89 | res.set_content(result, "application/json");
90 | return;
91 | }
92 | SET_CONTENT(({false}));
93 | },
94 | "", "executes arbitrary lua. used only for debugging"});
95 | #endif
96 | }
97 |
--------------------------------------------------------------------------------
/X4_Rest_Reloaded/endpoint_impl/logbook_funcs.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2021-2023 Peter Repukat - FlatspotSoftware
3 |
4 | Use of this source code is governed by the MIT
5 | license that can be found in the LICENSE file or at
6 | https://opensource.org/licenses/MIT.
7 | */
8 |
9 | #pragma once
10 |
11 | #include "../httpserver/HttpServer.h"
12 | #include "../ffi/FFIInvoke.h"
13 |
14 | #include "../ffi/ffi_enum_helper.h"
15 |
16 | #include "../_lua_.h"
17 |
18 | inline void RegisterLogbookFunctions(INIT_PARAMS()) {
19 |
20 |
21 | HttpServer::AddEndpoint({"/GetNumLogbook", HttpServer::Method::GET,
22 | [ & ](const httplib::Request& req, httplib::Response& res) {
23 | const auto category = req.get_param_value("category");
24 |
25 | if (category.empty()) {
26 | return BadRequest(res, "category is required");
27 | }
28 |
29 | if (!LogbookCategory::is_valid(category)) {
30 | return BadRequest(res, "category is invalid; Valid categories: 'all', 'general', 'missions', 'news', "
31 | "'alerts', 'upkeep', 'tips'");
32 | }
33 |
34 | if (ui_lua_state != nullptr) {
35 | const auto result = executeLua("return GetNumLogbook(\"" + category + "\")", false, false);
36 | res.set_content(result, "application/json");
37 | return;
38 | }
39 | SET_CONTENT((nullptr));
40 | },
41 | "number"});
42 |
43 |
44 | HttpServer::AddEndpoint({"/GetLogbook", HttpServer::Method::GET,
45 | [ & ](const httplib::Request& req, httplib::Response& res) {
46 | const auto category = req.get_param_value("category");
47 |
48 | if (category.empty()) {
49 | return BadRequest(res, "category is required");
50 | }
51 |
52 | if (!LogbookCategory::is_valid(category)) {
53 | return BadRequest(res, "category is invalid; Valid categories: 'all', 'general', 'missions', 'news', "
54 | "'alerts', 'upkeep', 'tips'");
55 | }
56 |
57 | size_t page = 1;
58 |
59 | try {
60 | page = std::stoul(req.get_param_value("page"));
61 | }
62 | catch (...) {
63 | // ignore
64 | }
65 | //if (page <= 0) {
66 | // page = 1;
67 | //}
68 |
69 | if (ui_lua_state != nullptr) {
70 | // "inspiration" from gamefiles /ui/addons/ego_detailmonitor/menu_playerinfo.lua
71 |
72 | if (page == 0)
73 | {
74 | std::string lua = R"(local logbook = {}
75 | local numEntries = GetNumLogbook(")" + category +
76 | R"(")
77 | local queries = math.ceil(numEntries / 500)
78 | for i=0,queries do
79 | table.insert(logbook, GetLogbook(i*500+1, 500, ")" +
80 | category + R"("))
81 | end
82 | return json.encode(logbook))";
83 | const auto result = executeLua(lua, true, true);
84 | res.set_content(result, "application/json");
85 | return;
86 | }
87 |
88 | std::string lua = R"(
89 | local numEntries = GetNumLogbook( ")" +
90 | category + R"(" )
91 | local logbook = {}
92 | local startIndex = 0
93 | local numQuery = math.min(100, numEntries)
94 | local curPage = )" +
95 | std::to_string(page) + R"(
96 | if numEntries <= 100 then
97 | curPage = 1
98 | else
99 | startIndex = numEntries - 100 * curPage + 1
100 | if startIndex < 1 then
101 | numQuery = 100 + startIndex - 1
102 | startIndex = 1
103 | end
104 | end
105 | logbook = GetLogbook(startIndex, numQuery, ")" +
106 | category + R"(")
107 | return json.encode(logbook)
108 | )";
109 |
110 | const auto result = executeLua(lua, true, true);
111 | res.set_content(result, "application/json");
112 | return;
113 | }
114 | SET_CONTENT(({}));
115 | },
116 | "number"});
117 | }
--------------------------------------------------------------------------------
/X4_Rest_Reloaded/endpoint_impl/map_or_query_funcs.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2021-2023 Peter Repukat - FlatspotSoftware
3 |
4 | Use of this source code is governed by the MIT
5 | license that can be found in the LICENSE file or at
6 | https://opensource.org/licenses/MIT.
7 | */
8 |
9 | #include "../httpserver/HttpServer.h"
10 | #include "../ffi/FFIInvoke.h"
11 |
12 | #include "../ffi/ffi_enum_helper.h"
13 |
14 | #include "../ffi/json_converters.h"
15 |
16 |
17 | inline void RegisterMapOrQueryFunctions(INIT_PARAMS()) {
18 | HttpServer::AddEndpoint(SIMPLE_GET_HANDLER(GetNumAllRaces));
19 |
20 | HttpServer::AddEndpoint({"/GetNumAllFactions", HttpServer::Method::GET,
21 | [ & ](const httplib::Request& req, httplib::Response& res) {
22 | bool include_hidden = false;
23 |
24 | try {
25 | const auto hidden_param = req.get_param_value("hidden");
26 | include_hidden = hidden_param == "true" || hidden_param == "1";
27 | }
28 | catch (...) {
29 | // ignore
30 | }
31 |
32 | const auto numFactions = invoke(GetNumAllFactions, include_hidden);
33 | SET_CONTENT((numFactions));
34 | }});
35 |
36 | HttpServer::AddEndpoint({"/GetAllRaces", HttpServer::Method::GET,
37 | [ & ](const httplib::Request& req, httplib::Response& res) {
38 | const auto numRaces = invoke(GetNumAllRaces);
39 | std::vector result;
40 | result.resize(numRaces);
41 | const auto callResult = invoke(GetAllRaces, result.data(), result.size());
42 | SET_CONTENT((result));
43 | }});
44 |
45 | HttpServer::AddEndpoint({"/GetAllFactions", HttpServer::Method::GET,
46 | [ & ](const httplib::Request& req, httplib::Response& res) {
47 | bool include_hidden = false;
48 |
49 | try {
50 | const auto hidden_param = req.get_param_value("hidden");
51 | include_hidden = hidden_param == "true" || hidden_param == "1";
52 | }
53 | catch (...) {
54 | // ignore
55 | }
56 |
57 | const auto numFactions = invoke(GetNumAllFactions, include_hidden);
58 | std::vector result;
59 | result.resize(numFactions);
60 | const auto callResult = invoke(
61 | GetAllFactions, (const char**)result.data(), result.size(), include_hidden);
62 | SET_CONTENT((result));
63 | }});
64 |
65 | HttpServer::AddEndpoint({"/GetAllFactionShips", HttpServer::Method::GET,
66 | [ & ](const httplib::Request& req, httplib::Response& res) {
67 | std::string factionId = "";
68 | try {
69 | factionId = req.get_param_value("factionId");
70 | }
71 | catch (...) {
72 | // ignore
73 | }
74 | const auto numFactions = invoke(GetNumAllFactions, true);
75 | std::vector factions;
76 | factions.resize(numFactions);
77 | invoke(GetAllFactions, (const char**)factions.data(), factions.size(), true);
78 |
79 | if (std::ranges::find_if(factions, [ & ](const auto f) {
80 | return f == factionId;
81 | }) == std::ranges::end(factions)) {
82 | return BadRequest(res, "factionId is invalid");
83 | }
84 |
85 | const auto numShips = invoke(GetNumAllFactionShips, factionId.c_str());
86 | std::vector result;
87 | result.resize(numShips);
88 |
89 | invoke(GetAllFactionShips, result.data(), result.size(), factionId.c_str());
90 | SET_CONTENT((result));
91 | }});
92 |
93 | HttpServer::AddEndpoint({"/GetAllFactionStations", HttpServer::Method::GET,
94 | [ & ](const httplib::Request& req, httplib::Response& res) {
95 | std::string factionId = "";
96 | try {
97 | factionId = req.get_param_value("factionId");
98 | }
99 | catch (...) {
100 | // ignore
101 | }
102 | const auto numFactions = invoke(GetNumAllFactions, true);
103 | std::vector factions;
104 | factions.resize(numFactions);
105 | invoke(GetAllFactions, (const char**)factions.data(), factions.size(), true);
106 |
107 | if (std::ranges::find_if(factions, [ & ](const auto f) {
108 | return f == factionId;
109 | }) == std::ranges::end(factions)) {
110 | return BadRequest(res, "factionId is invalid");
111 | }
112 |
113 | const auto numShips = invoke(GetNumAllFactionStations, factionId.c_str());
114 | std::vector result;
115 | result.resize(numShips);
116 |
117 | invoke(GetAllFactionStations, result.data(), result.size(), factionId.c_str());
118 | SET_CONTENT((result));
119 | }});
120 |
121 |
122 | HttpServer::AddEndpoint({"/GetSectorShips", HttpServer::Method::GET,
123 | [ & ](const httplib::Request& req, httplib::Response& res) {
124 | const X4FFI::UniverseID sectorId = HttpServer::ParseQueryParam(req, "sectorId", 0);
125 | if (sectorId == 0) {
126 | return BadRequest(res, "sectorId is invalid");
127 | }
128 | const bool includeHidden = HttpServer::ParseQueryParam(req, "hidden", false);
129 | const auto numFactions = invoke(GetNumAllFactions, includeHidden);
130 | std::vector allFactions;
131 | allFactions.resize(numFactions);
132 | invoke(GetAllFactions, (const char**)allFactions.data(), allFactions.size(),
133 | includeHidden);
134 | std::string shipIdsString = "";
135 | for (const auto& faction : allFactions) {
136 | const auto numShips = invoke(GetNumAllFactionShips, faction);
137 | std::vector factionShipIds;
138 | factionShipIds.resize(numShips);
139 | invoke(
140 | GetAllFactionShips, factionShipIds.data(), factionShipIds.size(), faction);
141 | for (const auto& ship : factionShipIds) {
142 | shipIdsString += std::to_string(ship) + ",";
143 | }
144 | }
145 | shipIdsString.pop_back();
146 |
147 | const auto lua_str = std::string(R"(
148 | local resultTable = {}
149 | local sectorId = "ID: )") + std::to_string(sectorId) + R"("
150 | local shipIds = {)" + shipIdsString +
151 | R"(}
152 |
153 | for i, ship in ipairs(shipIds) do
154 | local data = {GetComponentData(ship, "name","sectorid","owner","shiptype")}
155 | if tostring(data[2]) == sectorId then
156 | table.insert(resultTable, {
157 | ["id"] = ship,
158 | ["name"] = data[1],
159 | ["sectorid"] = data[2],
160 | ["owner"] = data[3],
161 | ["shiptype"] = data[4]
162 | })
163 | end
164 | end
165 |
166 |
167 | return json.encode(resultTable)
168 | )";
169 | const auto callResult = executeLua(lua_str, true, true);
170 | res.set_content(callResult, "application/json");
171 | }});
172 | }
--------------------------------------------------------------------------------
/X4_Rest_Reloaded/endpoint_impl/message_funcs.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2021-2023 Peter Repukat - FlatspotSoftware
3 |
4 | Use of this source code is governed by the MIT
5 | license that can be found in the LICENSE file or at
6 | https://opensource.org/licenses/MIT.
7 | */
8 |
9 | #pragma once
10 |
11 | #include "../httpserver/HttpServer.h"
12 | #include "../ffi/FFIInvoke.h"
13 |
14 | #include "../ffi/ffi_enum_helper.h"
15 |
16 | #include "../ffi/json_converters.h"
17 |
18 | inline void RegisterMessageFunctions(INIT_PARAMS()) {
19 |
20 | HttpServer::AddEndpoint(
21 | {"/GetNumMessages", HttpServer::Method::GET, [ & ](const httplib::Request& req, httplib::Response& res) {
22 | const auto category = req.get_param_value("category");
23 |
24 | if (category.empty()) {
25 | return BadRequest(res, "category is required");
26 | }
27 |
28 | if (!MessageCategory::is_valid(category)) {
29 | return BadRequest(res, "category is invalid; Valid categories: 'all', 'highprio', 'lowprio'");
30 | }
31 |
32 | bool unread = false;
33 | const auto lastParam = req.get_param_value("unread");
34 | if (lastParam == "1" || lastParam == "true") {
35 | unread = true;
36 | }
37 |
38 |
39 | const auto callResult = invoke(GetNumMessages, category.c_str(), unread);
40 | SET_CONTENT((callResult));
41 | }});
42 |
43 | // using GetMessages = uint32_t (*)(
44 | // MessageInfo* result, uint32_t resultlen, size_t start, size_t count, const char* categoryname);
45 |
46 | HttpServer::AddEndpoint(
47 | {"/GetMessages", HttpServer::Method::GET, [ & ](const httplib::Request& req, httplib::Response& res) {
48 | const auto category = req.get_param_value("category");
49 |
50 | if (category.empty()) {
51 | return BadRequest(res, "category is required");
52 | }
53 |
54 | if (!MessageCategory::is_valid(category)) {
55 | return BadRequest(res, "category is invalid; Valid categories: 'all', 'highprio', 'lowprio'");
56 | }
57 |
58 | size_t from = 0;
59 | size_t count = 0;
60 |
61 | try {
62 | from = std::stoul(req.get_param_value("from"));
63 | }
64 | catch (...) {
65 | // ignore
66 | }
67 | try {
68 | count = std::stoul(req.get_param_value("count"));
69 | }
70 | catch (...) {
71 | // ignore
72 | }
73 |
74 |
75 | std::vector messages;
76 |
77 | const auto numMessages = invoke(GetNumMessages, category.c_str(), false);
78 | if (from > numMessages) {
79 | from = numMessages;
80 | }
81 | if (count == 0) {
82 | count = numMessages;
83 | }
84 | count = std::clamp(count, static_cast(0),
85 | std::max(static_cast(0), (numMessages + (from == 0 ? 0 : 1)) - from));
86 |
87 | messages.resize(count);
88 |
89 | const auto length = invoke(GetMessages, messages.data(), messages.size(), from, count, category.c_str());
90 | SET_CONTENT(({{"length", length}, {"messages", messages}}));
91 | }});
92 | }
93 |
--------------------------------------------------------------------------------
/X4_Rest_Reloaded/endpoint_impl/object_and_component_funcs.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2021-2023 Peter Repukat - FlatspotSoftware
3 |
4 | Use of this source code is governed by the MIT
5 | license that can be found in the LICENSE file or at
6 | https://opensource.org/licenses/MIT.
7 | */
8 |
9 | #pragma once
10 |
11 | #include "../httpserver/HttpServer.h"
12 | #include "../ffi/FFIInvoke.h"
13 |
14 | #include "../_lua_.h"
15 |
16 | #include "../lua_scripts/ComponentDataHelper.h"
17 |
18 |
19 | inline void RegisterObjectAndComponentFunctions(INIT_PARAMS()) {
20 | HttpServer::AddEndpoint(UINT64_PARAM_GET_HANDLER(GetObjectIDCode, "objectId"));
21 | HttpServer::AddEndpoint(UINT64_PARAM_GET_HANDLER(GetObjectPositionInSector, "objectId"));
22 |
23 | HttpServer::AddEndpoint(UINT64_PARAM_GET_HANDLER(GetComponentClass, "componentId"));
24 | HttpServer::AddEndpoint(UINT64_PARAM_GET_HANDLER(GetComponentName, "componentId"));
25 |
26 | HttpServer::AddEndpoint(UINT64_PARAM_GET_HANDLER(IsObjectKnown, "componentId"));
27 |
28 | HttpServer::AddEndpoint({"/IsComponentClass", HttpServer::Method::GET,
29 | [&](const httplib::Request& req, httplib::Response& res)
30 | {
31 | uint64_t componentId;
32 | try {
33 | componentId = std::stoull(req.get_param_value("componentId"));
34 | }
35 | catch (...) {
36 | return BadRequest(res, "componentId is invalid");
37 | }
38 | if (componentId == 0) {
39 | return BadRequest(res, "componentId is required");
40 | }
41 |
42 | std::string component_class;
43 | try {
44 | component_class = req.get_param_value("componentClass");
45 | }
46 | catch (...) {
47 | return BadRequest(res, "componentClass is required");
48 | }
49 | if (component_class.empty())
50 | {
51 | return BadRequest(res, "componentClass is required");
52 | }
53 |
54 | const auto callResult = invoke(IsComponentClass, componentId, component_class.c_str());
55 | SET_CONTENT((callResult));
56 |
57 | }
58 | });
59 |
60 | HttpServer::AddEndpoint({"/GetComponentData", HttpServer::Method::GET,
61 | [](const httplib::Request& req, httplib::Response& res) {
62 | uint64_t componentId;
63 | try {
64 | componentId = std::stoull(req.get_param_value("componentId"));
65 | }
66 | catch (...) {
67 | return BadRequest(res, "componentId is invalid");
68 | }
69 | if (componentId == 0)
70 | {
71 | return BadRequest(res, "componentId is required");
72 | }
73 |
74 | std::string attribs;
75 |
76 | try {
77 | attribs = req.get_param_value("attribs");
78 | }
79 | catch (...) {
80 | return BadRequest(res, "attribs are required");
81 | }
82 |
83 | if (attribs.empty()) {
84 | return BadRequest(res, "attribs are required");
85 | }
86 |
87 | std::string lua_attribs = "";
88 |
89 | for (auto attr : std::views::split(attribs, ',')) {
90 | const auto attr_str = std::string(attr.begin(), attr.end());
91 | if (!is_valid_component_data(attr_str)) {
92 | res.status = 401;
93 | SET_CONTENT(({{"code", 401}, {"name", "Bad Request"},
94 | {"message", "attrib \"" + attr_str + "\" is invalid"}, {"valid_attributes", valid_component_data_attribs}}));
95 | return;
96 | }
97 | lua_attribs += "\"" + attr_str + "\",";
98 | }
99 |
100 | lua_attribs.pop_back();
101 |
102 | if (ui_lua_state != nullptr) {
103 | const auto lua_str =
104 | std::string("local querieddata = {GetComponentData(" + std::to_string(componentId) + ",") +
105 | lua_attribs +
106 | " )}\n" + "return json.encode(querieddata)";
107 | const auto callResult = executeLua(lua_str, true, true);
108 | res.set_content(callResult, "application/json");
109 | return;
110 | }
111 | SET_CONTENT(({}));
112 | },
113 | "array"});
114 | }
--------------------------------------------------------------------------------
/X4_Rest_Reloaded/endpoint_impl/player_funcs.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2021-2023 Peter Repukat - FlatspotSoftware
3 |
4 | Use of this source code is governed by the MIT
5 | license that can be found in the LICENSE file or at
6 | https://opensource.org/licenses/MIT.
7 | */
8 |
9 | #pragma once
10 |
11 | #include "../httpserver/HttpServer.h"
12 | #include "../ffi/FFIInvoke.h"
13 |
14 | #include "../_lua_.h"
15 |
16 |
17 | inline void RegisterPlayerFunctions(INIT_PARAMS()) {
18 |
19 | HttpServer::AddEndpoint(SIMPLE_GET_HANDLER(GetPlayerComputerID));
20 | HttpServer::AddEndpoint(SIMPLE_GET_HANDLER(GetPlayerContainerID));
21 | HttpServer::AddEndpoint(SIMPLE_GET_HANDLER(GetPlayerControlledShipID));
22 | HttpServer::AddEndpoint(SIMPLE_GET_HANDLER(GetPlayerID));
23 | HttpServer::AddEndpoint(SIMPLE_GET_HANDLER(GetPlayerObjectID));
24 | HttpServer::AddEndpoint(SIMPLE_GET_HANDLER(GetPlayerOccupiedShipID));
25 |
26 | HttpServer::AddEndpoint(SIMPLE_GET_HANDLER(GetPlayerTargetOffset));
27 | HttpServer::AddEndpoint(SIMPLE_GET_HANDLER(GetSofttarget));
28 |
29 | HttpServer::AddEndpoint(SIMPLE_GET_HANDLER(GetCreditsDueFromPlayerBuilds));
30 | HttpServer::AddEndpoint(SIMPLE_GET_HANDLER(GetCreditsDueFromPlayerTrades));
31 |
32 | HttpServer::AddEndpoint(SIMPLE_GET_HANDLER(GetPlayerName));
33 | HttpServer::AddEndpoint({"/GetPlayerFactionName", HttpServer::Method::GET,
34 | [ & ](const httplib::Request& req, httplib::Response& res) {
35 | bool userawname = false;
36 | const auto userawnameParam = req.get_param_value("userawname");
37 | if (userawnameParam == "1" || userawnameParam == "true") {
38 | userawname = true;
39 | }
40 |
41 | const auto callResult = invoke(GetPlayerFactionName, userawname);
42 | SET_CONTENT((callResult));
43 | }});
44 |
45 | HttpServer::AddEndpoint(SIMPLE_GET_HANDLER(GetPlayerZoneID));
46 |
47 | HttpServer::AddEndpoint({"/GetStats", HttpServer::Method::GET,
48 | [ & ](const httplib::Request& req, httplib::Response& res) {
49 | bool include_hidden = false;
50 |
51 | try {
52 | const auto hidden_param = req.get_param_value("hidden");
53 | include_hidden = hidden_param == "true" || hidden_param == "1";
54 | }
55 | catch (...) {
56 | // ignore
57 | }
58 |
59 | if (ui_lua_state != nullptr) {
60 | const auto get_stats_lua =
61 | R"(
62 | local statTable = {}
63 | local stats = GetAllStatIDs()
64 | for i = 1, #stats do
65 | local hidden, displayname = GetStatData(stats[i], "hidden", "displayname")
66 | if not hidden then
67 | statTable[stats[i]] = GetStatData(stats[i], "displayvalue")
68 | else
69 | )" + std::string{include_hidden ? "" : "-- "} +
70 | R"(statTable["hidden:" .. stats[i]] = GetStatData(stats[i], "displayvalue")
71 | end
72 | end
73 |
74 | return json.encode(statTable)
75 | )";
76 | const auto callResult = executeLua(get_stats_lua, true, true);
77 | res.set_content(callResult, "application/json");
78 | return;
79 | }
80 | SET_CONTENT(({}));
81 | }});
82 |
83 | HttpServer::AddEndpoint({"/GetPlayerMoney", HttpServer::Method::GET,
84 | [ & ](const httplib::Request& req, httplib::Response& res) {
85 | if (ui_lua_state != nullptr) {
86 | const auto get_stats_lua = R"(return json.encode(GetPlayerMoney()))";
87 | const auto callResult = executeLua(get_stats_lua, true, true);
88 | res.set_content(callResult, "application/json");
89 | return;
90 | }
91 | SET_CONTENT(({}));
92 | }});
93 | }
94 |
--------------------------------------------------------------------------------
/X4_Rest_Reloaded/ffi/FFIInvoke.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2021-2023 Peter Repukat - FlatspotSoftware
3 |
4 | Use of this source code is governed by the MIT
5 | license that can be found in the LICENSE file or at
6 | https://opensource.org/licenses/MIT.
7 | */
8 |
9 | #include "FFIInvoke.h"
10 | #ifdef _WIN32
11 | FFIInvoke::FFIInvoke(const HMODULE x4_module) { x4_module_ = x4_module; }
12 | #else
13 | #include
14 | #endif
15 |
16 | void FFIInvoke::loadFunction(const char* name)
17 | {
18 | #ifdef _WIN32
19 | const auto addr = GetProcAddress(x4_module_, name);
20 | #else
21 | const auto addr = dlsym(RTLD_DEFAULT, name);
22 | #endif
23 | if (!addr) {
24 | #ifdef _WIN32
25 | throw std::exception(std::string(std::string(name) + " not found").c_str());
26 | #else
27 | throw std::exception(); // exception with message ctor is M$ extension
28 | #endif
29 | }
30 | funcs_[name] = addr;
31 | }
32 |
--------------------------------------------------------------------------------
/X4_Rest_Reloaded/ffi/FFIInvoke.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2021-2023 Peter Repukat - FlatspotSoftware
3 |
4 | Use of this source code is governed by the MIT
5 | license that can be found in the LICENSE file or at
6 | https://opensource.org/licenses/MIT.
7 | */
8 |
9 | #pragma once
10 | #ifdef _WIN32
11 | #include
12 | #endif
13 | #include
14 | #include
15 | #include
16 |
17 | #include "x4ffi/ffi_funcs.h"
18 |
19 | #define Q(x) #x
20 | #define QUOTE(x) Q(x)
21 |
22 | #define INIT_PARAMS(...) FFIInvoke &ffi_invoke, ##__VA_ARGS__
23 |
24 | #define invoke(FuncName, ...) ffi_invoke.invokeFn(QUOTE(FuncName), ##__VA_ARGS__)
25 |
26 | /**
27 | * Loads and invokes FFI functions from the game
28 | */
29 | class FFIInvoke {
30 | public:
31 | #ifdef _WIN32
32 | explicit FFIInvoke(const HMODULE x4_module);
33 | #else
34 | FFIInvoke() = default;
35 | #endif
36 |
37 | template decltype(auto) invokeFn(const char* funcname, Args... args)
38 | {
39 | if (!funcs_.contains(funcname)) {
40 | loadFunction(funcname);
41 | }
42 | return reinterpret_cast(funcs_[funcname])(args...);
43 | };
44 |
45 | private:
46 | #ifdef _WIN32
47 | HMODULE x4_module_;
48 | #endif
49 | std::unordered_map funcs_; // map holding funcs by name
50 | /**
51 | * Actually loads a given FFI-function by name
52 | */
53 | void loadFunction(const char* name);
54 | };
--------------------------------------------------------------------------------
/X4_Rest_Reloaded/ffi/ffi_enum_helper.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 |
4 | // FUCK c++ enums!
5 |
6 | namespace MessageCategory {
7 | using Type = std::string;
8 | Type all = "all";
9 | Type highprio = "highprio";
10 | Type lowprio = "lowprio";
11 |
12 | inline bool is_valid(const Type& type) {
13 | return type == all || type == highprio || type == lowprio;
14 | }
15 | }
16 |
17 | namespace LogbookCategory {
18 | using Type = std::string;
19 | Type all = "all";
20 | Type general = "general";
21 | Type missions = "missions";
22 | Type news = "news";
23 | Type alerts = "alerts";
24 | Type upkeep = "upkeep";
25 | Type tips = "tips";
26 |
27 | inline bool is_valid(const Type& type) {
28 | return type == all || type == general || type == missions || type == news ||
29 | type == alerts || type == upkeep || type == tips;
30 | }
31 | }
32 |
33 | namespace ComponentClasses {
34 | using Type = std::string;
35 | Type ship = "ship";
36 | Type ship_xs = "ship_xs";
37 | Type ship_s = "ship_s";
38 | Type ship_m = "ship_m";
39 | Type ship_l = "ship_l";
40 | Type ship_xl = "ship_xl";
41 | Type station = "station";
42 | Type controllable = "controllable";
43 | Type isdeployable = "isdeployable";
44 | Type lockbox = "lockbox";
45 | Type container = "container";
46 | Type object = "object";
47 | Type sector = "sector";
48 | Type gate = "gate";
49 | Type mine = "mine";
50 | Type navbeacon = "navbeacon";
51 | Type resourceprobe = "resourceprobe";
52 | Type satellite = "satellite";
53 | Type asteroid = "asteroid";
54 | Type collectablewares = "collectablewares";
55 |
56 | inline bool is_valid(const Type& type) {
57 | return type == ship || type == ship_xs || type == ship_s || type == ship_m ||
58 | type == ship_l || type == ship_xl || type == station || type == controllable ||
59 | type == isdeployable || type == lockbox || type == container || type == object ||
60 | type == sector || type == gate || type == mine || type == navbeacon ||
61 | type == resourceprobe || type == satellite || type == asteroid ||
62 | type == collectablewares;
63 | }
64 | }
--------------------------------------------------------------------------------
/X4_Rest_Reloaded/ffi/json_converters.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 |
4 | #include "x4ffi/ffi_typedef_struct.h"
5 |
6 | using json = nlohmann::json;
7 |
8 | namespace X4FFI {
9 | inline void to_json(json& j, const MessageInfo& m) {
10 | j = nlohmann::json{
11 | {"id", m.id},
12 | {"time", m.time},
13 | {"category", m.category},
14 | {"title", m.title},
15 | {"text", m.text},
16 | {"source", m.source},
17 | {"sourcecomponent", m.sourcecomponent},
18 | {"interaction", m.interaction},
19 | {"interactioncomponent", m.interactioncomponent},
20 | {"interactiontext", m.interactiontext},
21 | {"interactionshorttext", m.interactionshorttext},
22 | {"cutscenekey", m.cutscenekey},
23 | {"entityname", m.entityname},
24 | {"factionname", m.factionname},
25 | {"money", m.money},
26 | {"bonus", m.bonus},
27 | {"highlighted", m.highlighted},
28 | {"isread", m.isread},
29 | };
30 | }
31 |
32 | inline void to_json(json& j, const UIPosRot& m) {
33 | j = nlohmann::json{{"x", m.x}, {"y", m.y}, {"z", m.z}, {"pitch", m.pitch},
34 | {"yaw", m.yaw}, {"roll", m.roll}};
35 | };
36 |
37 | inline void to_json(json& j, const SofttargetDetails& s) {
38 | j = nlohmann::json{
39 | {"softtargetID", s.softtargetID},
40 | {"softtargetConnectionName", s.softtargetConnectionName},
41 | };
42 | }
43 | inline void to_json(json& j, const RaceInfo& r) {
44 | j = nlohmann::json{{"id", r.id}, {"name", r.name}, {"shortname", r.shortname},
45 | {"description", r.description}, {"icon", r.icon}};
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/X4_Rest_Reloaded/ffi/x4ffi/ffi_funcs.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | // Regex to convert the lua definitions to c++ typedefs
4 | // \t(.+?)(([0-z])+?)\(
5 | // using $2 = $1(*)(
6 |
7 | #include "ffi_funcs_menu_map.h"
8 | #include "ffi_funcs_menu_playerinfo.h"
9 | #include "ffi_funcs_helper.h"
10 | #include "ffi_funcs_station_config.h"
11 | #include "ffi_funcs_customgame.h"
--------------------------------------------------------------------------------
/X4_Rest_Reloaded/ffi/x4ffi/ffi_funcs_customgame.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "ffi_typedef.h"
3 | #include "ffi_typedef_struct.h"
4 |
5 | // Regex to convert the lua definitions to c++ typedefs
6 | // \t(.+?)(([0-z])+?)\(
7 | // using $2 = $1(*)(
8 |
9 | namespace X4FFI {
10 | using AreConstructionPlanLoadoutsCompatible = bool (*)(const char* constructionplanid);
11 | using CanPlayerUseRace = bool (*)(const char* raceid, const char* postid);
12 | using ExportCustomGameStart = void (*)(
13 | const char* filename, const char* id, const char* name);
14 | using GenerateFactionRelationTextFromRelation = const char* (*)(int32_t uirelation);
15 | using GetAllFactions = uint32_t (*)(
16 | const char** result, uint32_t resultlen, bool includehidden);
17 | using GetAllRaces = uint32_t (*)(RaceInfo* result, uint32_t resultlen);
18 | // using GetAvailableCustomGameStarts = uint32_t (*)(CustomGameStartInfo* result, uint32_t
19 | // resultlen, const char* id);
20 | using GetConstructionPlanInfo = size_t (*)(
21 | UIConstructionPlanEntry* result, size_t resultlen, const char* constructionplanid);
22 | // using GetCustomGameStartBlueprintDefaultProperty = uint32_t (*)(CustomGameStartBlueprint*
23 | // result, uint32_t resultlen, const char* id, const char* propertyid); using
24 | // GetCustomGameStartBlueprintProperty = uint32_t (*)(CustomGameStartBlueprint* result,
25 | // uint32_t resultlen, const char* id, const char* propertyid); using
26 | // GetCustomGameStartBlueprintPropertyState = CustomGameStartBlueprintPropertyState
27 | // (*)(const char* id, const char* propertyid); using GetCustomGameStartBoolProperty = bool
28 | // (*)(const char* id, const char* propertyid, CustomGameStartBoolPropertyState* state);
29 | // using GetCustomGameStartBudget = CustomGameStartBudgetInfo (*)(const char* id, const
30 | // char* budgetid); using GetCustomGameStartBudgetDetails = uint32_t
31 | // (*)(CustomGameStartBudgetDetail* result, uint32_t resultlen, const char* id, const char*
32 | // budgetid); using GetCustomGameStartBudgetGroupInfo = CustomGameStartBudgetGroupInfo
33 | // (*)(const char* id, const char* budgetgroupid);
34 | using GetCustomGameStartBudgetGroups = uint32_t (*)(
35 | const char** result, uint32_t resultlen, const char* id);
36 | // using GetCustomGameStartEncyclopediaProperty = uint32_t
37 | // (*)(CustomGameStartEncyclopediaEntry* result, uint32_t resultlen, const char* id, const
38 | // char* propertyid);
39 | using GetCustomGameStartEncyclopediaPropertyCounts = uint32_t (*)(
40 | const char* id, const char* propertyid);
41 | // using GetCustomGameStartEncyclopediaPropertyState =
42 | // CustomGameStartEncyclopediaPropertyState (*)(const char* id, const char* propertyid);
43 | // using GetCustomGameStartInventoryDefaultProperty = uint32_t (*)(CustomGameStartInventory*
44 | // result, uint32_t resultlen, const char* id, const char* propertyid); using
45 | // GetCustomGameStartInventoryProperty = uint32_t (*)(CustomGameStartInventory* result,
46 | // uint32_t resultlen, const char* id, const char* propertyid); using
47 | // GetCustomGameStartInventoryPropertyState = CustomGameStartInventoryPropertyState
48 | // (*)(const char* id, const char* propertyid); using
49 | // GetCustomGameStartKnownDefaultProperty2 = uint32_t (*)(CustomGameStartKnownEntry2*
50 | // result, uint32_t resultlen, const char* id, const char* propertyid); using
51 | // GetCustomGameStartKnownProperty2 = uint32_t (*)(CustomGameStartKnownEntry2* result,
52 | // uint32_t resultlen, const char* id, const char* propertyid); using
53 | // GetCustomGameStartKnownPropertyBudgetValue2 = bool (*)(const char* id, const char*
54 | // propertyid, CustomGameStartKnownEntry2* uivalue); using
55 | // GetCustomGameStartKnownPropertyNumStateDependencies = uint32_t (*)(uint32_t* result,
56 | // uint32_t resultlen, const char* id, const char* propertyid, CustomGameStartKnownEntry2
57 | // uivalue); using GetCustomGameStartKnownPropertyNumStateDependencyLists = uint32_t
58 | // (*)(const char* id, const char* propertyid, CustomGameStartKnownEntry2 uivalue); using
59 | // GetCustomGameStartKnownPropertyState = CustomGameStartKnownPropertyState (*)(const char*
60 | // id, const char* propertyid); using GetCustomGameStartKnownPropertyStateDependencies =
61 | // uint32_t (*)(const char** result, uint32_t resultlen, const char* id, const char*
62 | // propertyid, CustomGameStartKnownEntry2 uivalue); using GetCustomGameStartContentCounts =
63 | // CustomGameStartContentCounts (*)(const char* id, const char* filename, const char*
64 | // gamestartid); using GetCustomGameStartContent = void (*)(CustomGameStartContentData*
65 | // result, const char* id, const char* filename, const char* gamestartid); using
66 | // GetCustomGameStartMoneyProperty = int64_t (*)(const char* id, const char* propertyid,
67 | // CustomGameStartMoneyPropertyState* state);
68 | using GetCustomGameStartPaintThemes = uint32_t (*)(
69 | UIPaintTheme* result, uint32_t resultlen, const char* id);
70 | // using GetCustomGameStartPlayerPropertyCounts = uint32_t
71 | // (*)(CustomGameStartPlayerPropertyCounts* result, uint32_t resultlen, const char* id,
72 | // const char* propertyid);
73 | using GetCustomGameStartPlayerPropertyPeopleValue = int64_t (*)(
74 | const char* id, const char* propertyid, const char* entryid);
75 | // using GetCustomGameStartPlayerPropertyPerson = bool (*)(CustomGameStartPersonEntry*
76 | // result, const char* id, const char* propertyid, const char* entryid); using
77 | // GetCustomGameStartPlayerPropertyProperty3 = uint32_t (*)(CustomGameStartPlayerProperty3*
78 | // result, uint32_t resultlen, const char* id, const char* propertyid); using
79 | // GetCustomGameStartPlayerPropertyPropertyState =
80 | // CustomGameStartPlayerPropertyPropertyState (*)(const char* id, const char* propertyid);
81 | using GetCustomGameStartPlayerPropertySector = const char* (*)(const char* id,
82 | const char* propertyid, const char* entryid);
83 | using GetCustomGameStartPlayerPropertyValue = int64_t (*)(
84 | const char* id, const char* propertyid, const char* entryid);
85 | // using GetCustomGameStartPosRotProperty = UIPosRot (*)(const char* id, const char*
86 | // propertyid, CustomGameStartPosRotPropertyState* state); using
87 | // GetCustomGameStartRelationsProperty = uint32_t (*)(CustomGameStartRelationInfo* result,
88 | // uint32_t resultlen, const char* id, const char* propertyid); using
89 | // GetCustomGameStartRelationsPropertyBudgetValue = int64_t (*)(const char* id, const char*
90 | // propertyid, CustomGameStartRelationInfo uivalue);
91 | using GetCustomGameStartRelationsPropertyCounts = uint32_t (*)(
92 | const char* id, const char* propertyid);
93 | // using GetCustomGameStartRelationsPropertyState = CustomGameStartRelationsPropertyState
94 | // (*)(const char* id, const char* propertyid);
95 | using GetCustomGameStartResearchProperty = uint32_t (*)(
96 | const char** result, uint32_t resultlen, const char* id, const char* propertyid);
97 | using GetCustomGameStartResearchPropertyCounts = uint32_t (*)(
98 | const char* id, const char* propertyid);
99 | // using GetCustomGameStartResearchPropertyState = CustomGameStartResearchPropertyState
100 | // (*)(const char* id, const char* propertyid); using GetCustomGameStartShipPersonValue =
101 | // int64_t (*)(const char* id, CustomGameStartPersonEntry uivalue); using
102 | // GetCustomGameStartStoryBudgets = uint32_t (*)(CustomGameStartStoryInfo* result, uint32_t
103 | // resultlen, const char* id);
104 | using GetNumCustomGameStartStoryBudgetDependencyLists = uint32_t (*)(
105 | uint32_t* result, uint32_t resultlen, const char* id, const char* storyid);
106 | using GetCustomGameStartStoryBudgetDependencies = uint32_t (*)(
107 | const char** result, uint32_t resultlen, const char* id, const char* storyid);
108 | using GetCustomGameStartStoryDefaultProperty = uint32_t (*)(
109 | const char** result, uint32_t resultlen, const char* id, const char* propertyid);
110 | using GetCustomGameStartStoryProperty = uint32_t (*)(
111 | const char** result, uint32_t resultlen, const char* id, const char* propertyid);
112 | // using GetCustomGameStartStoryPropertyState = CustomGameStartStoryState (*)(const char*
113 | // id, const char* propertyid); using GetCustomGameStartStringProperty = const char*
114 | // (*)(const char* id, const char* propertyid, CustomGameStartStringPropertyState* state);
115 | using GetMacroMapPositionOnEcliptic = const char* (*)(UniverseID holomapid,
116 | UIPosRot* position);
117 | using GetNumAllFactions = uint32_t (*)(bool includehidden);
118 | using GetNumAllRaces = uint32_t (*)(void);
119 | using GetNumAvailableCustomGameStarts = uint32_t (*)(const char* id);
120 | using GetNumConstructionPlanInfo = size_t (*)(const char* constructionplanid);
121 | using GetNumCustomGameStartBudgetGroups = uint32_t (*)(const char* id);
122 | using GetNumCustomGameStartPaintThemes = uint32_t (*)(const char* id);
123 | using GetNumCustomGameStartStoryBudgets = uint32_t (*)(const char* id);
124 | using GetNumPlannedLimitedModules = uint32_t (*)(const char* constructionplanid);
125 | using GetNumPlayerBuildMethods = uint32_t (*)(void);
126 | using GetNumWares = uint32_t (*)(
127 | const char* tags, bool research, const char* licenceownerid, const char* exclusiontags);
128 | using GetPlannedLimitedModules = uint32_t (*)(
129 | UIMacroCount* result, uint32_t resultlen, const char* constructionplanid);
130 | using GetPlayerBuildMethods = uint32_t (*)(
131 | ProductionMethodInfo* result, uint32_t resultlen);
132 | using GetStationValue = int64_t (*)(const char* macroname, const char* constructionplanid);
133 | using GetUIDefaultBaseRelation = int32_t (*)(
134 | const char* fromfactionid, const char* tofactionid);
135 | using GetWares = uint32_t (*)(const char** result, uint32_t resultlen, const char* tags,
136 | bool research, const char* licenceownerid, const char* exclusiontags);
137 | using HasCustomGameStartBudget = bool (*)(const char* id, const char* budgetid);
138 | using ImportCustomGameStart = void (*)(
139 | const char* id, const char* filename, const char* gamestartid);
140 | using IsConstructionPlanAvailableInCustomGameStart = bool (*)(
141 | const char* constructionplanid);
142 | using IsCustomGameStartPropertyChanged = bool (*)(const char* id, const char* propertyid);
143 | using IsGameStartModified = bool (*)(const char* id);
144 | using NewMultiplayerGame = void (*)(const char* modulename, const char* difficulty);
145 | using RemoveCustomGameStartPlayerProperty = void (*)(
146 | const char* id, const char* propertyid, const char* entryid);
147 | using RemoveHoloMap = void (*)(void);
148 | using ResetCustomGameStart = void (*)(const char* id);
149 | using ResetCustomGameStartProperty = void (*)(const char* id, const char* propertyid);
150 | // using SetCustomGameStartBlueprintProperty = void (*)(const char* id, const char*
151 | // propertyid, CustomGameStartBlueprint* uivalue, uint32_t uivaluecount);
152 | using SetCustomGameStartBoolProperty = void (*)(
153 | const char* id, const char* propertyid, bool uivalue);
154 | // using SetCustomGameStartEncyclopediaProperty = void (*)(const char* id, const char*
155 | // propertyid, CustomGameStartEncyclopediaEntry* uivalue, uint32_t uivaluecount); using
156 | // SetCustomGameStartInventoryProperty = void (*)(const char* id, const char* propertyid,
157 | // CustomGameStartInventory* uivalue, uint32_t uivaluecount); using
158 | // SetCustomGameStartKnownProperty2 = void (*)(const char* id, const char* propertyid,
159 | // CustomGameStartKnownEntry2* uivalue, uint32_t uivaluecount);
160 | using SetCustomGameStartMoneyProperty = void (*)(
161 | const char* id, const char* propertyid, int64_t uivalue);
162 | using SetCustomGameStartPlayerPropertyCount = void (*)(
163 | const char* id, const char* propertyid, const char* entryid, uint32_t count);
164 | using SetCustomGameStartPlayerPropertyObjectMacro = const char* (*)(const char* id,
165 | const char* propertyid, const char* entryid, const char* macroname);
166 | using SetCustomGameStartPlayerPropertyMacroAndConstructionPlan2 =
167 | const char* (*)(const char* id, const char* propertyid, const char* entryid,
168 | const char* macroname, const char* constructionplanid);
169 | using SetCustomGameStartPlayerPropertyName = void (*)(
170 | const char* id, const char* propertyid, const char* entryid, const char* name);
171 | using SetCustomGameStartPlayerPropertyPeople = void (*)(
172 | const char* id, const char* propertyid, const char* entryid, const char* peopledefid);
173 | using SetCustomGameStartPlayerPropertyPeopleFillPercentage2 = void (*)(
174 | const char* id, const char* propertyid, const char* entryid, float fillpercentage);
175 | // using SetCustomGameStartPlayerPropertyPerson = void (*)(const char* id, const char*
176 | // propertyid, const char* entryid, CustomGameStartPersonEntry uivalue);
177 | using SetCustomGameStartPlayerPropertySectorAndOffset = void (*)(const char* id,
178 | const char* propertyid, const char* entryid, const char* sectormacroname,
179 | UIPosRot uivalue);
180 | using SetCustomGameStartPosRotProperty = void (*)(
181 | const char* id, const char* propertyid, UIPosRot uivalue);
182 | // using SetCustomGameStartRelationsProperty = void (*)(const char* id, const char*
183 | // propertyid, CustomGameStartRelationInfo* uivalue, uint32_t uivaluecount);
184 | using SetCustomGameStartResearchProperty = void (*)(
185 | const char* id, const char* propertyid, const char** uivalue, uint32_t uivaluecount);
186 | using SetCustomGameStartShipAndEmptyLoadout = void (*)(const char* id,
187 | const char* shippropertyid, const char* loadoutpropertyid, const char* macroname);
188 | using SetCustomGameStartStringProperty = void (*)(
189 | const char* id, const char* propertyid, const char* uivalue);
190 | using SetCustomGameStartStory = void (*)(
191 | const char* id, const char* propertyid, const char** uivalue, uint32_t uivaluecount);
192 | using SetMacroMapLocalLinearHighways = void (*)(UniverseID holomapid, bool value);
193 | using SetMacroMapLocalRingHighways = void (*)(UniverseID holomapid, bool value);
194 | using SetMacroMapSelection = void (*)(
195 | UniverseID holomapid, bool selectplayer, const char* propertyentryid);
196 | using SetMapRelativeMousePosition = void (*)(
197 | UniverseID holomapid, bool valid, float x, float y);
198 | using ShowUniverseMacroMap2 = void (*)(UniverseID holomapid, const char* macroname,
199 | const char* startsectormacroname, UIPosRot sectoroffset, bool setoffset, bool showzone,
200 | const char* gamestartid);
201 | using StartPanMap = void (*)(UniverseID holomapid);
202 | using StopPanMap = bool (*)(UniverseID holomapid);
203 | using ZoomMap = void (*)(UniverseID holomapid, float zoomstep);
204 | }
--------------------------------------------------------------------------------
/X4_Rest_Reloaded/ffi/x4ffi/ffi_funcs_helper.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "ffi_typedef.h"
3 | #include "ffi_typedef_struct.h"
4 |
5 | // Regex to convert the lua definitions to c++ typedefs
6 | // \t(.+?)(([0-z])+?)\(
7 | // using $2 = $1(*)(
8 |
9 | namespace X4FFI {
10 | using AddTradeWare = void (*)(UniverseID containerid, const char* wareid);
11 | using AreVenturesEnabled = bool (*)(void);
12 | using CancelPlayerInvolvedTradeDeal = bool (*)(
13 | UniverseID containerid, TradeID tradeid, bool checkonly);
14 | using CanResearch = bool (*)(void);
15 | using ClearContainerBuyLimitOverride = void (*)(UniverseID containerid, const char* wareid);
16 | using ClearContainerSellLimitOverride = void (*)(
17 | UniverseID containerid, const char* wareid);
18 | using ClearTrackedMenus = void (*)(void);
19 | using DisableAutoMouseEmulation = void (*)(void);
20 | using EnableAutoMouseEmulation = void (*)(void);
21 | using GetAllBlacklists = uint32_t (*)(BlacklistID* result, uint32_t resultlen);
22 | using GetAllEquipmentModProperties = uint32_t (*)(
23 | EquipmentModPropertyInfo* result, uint32_t resultlen, const char* equipmentmodclass);
24 | using GetAllFightRules = uint32_t (*)(FightRuleID* result, uint32_t resultlen);
25 | using GetAllTradeRules = uint32_t (*)(TradeRuleID* result, uint32_t resultlen);
26 | using GetBlacklistInfoCounts = BlacklistCounts (*)(BlacklistID id);
27 | using GetBlacklistInfo2 = bool (*)(BlacklistInfo2* info, BlacklistID id);
28 | using GetCargoTransportTypes = uint32_t (*)(StorageInfo* result, uint32_t resultlen,
29 | UniverseID containerid, bool merge, bool aftertradeorders);
30 | using GetComponentName = const char* (*)(UniverseID componentid);
31 | using GetContainerBuyLimit = int32_t (*)(UniverseID containerid, const char* wareid);
32 | using GetContainerSellLimit = int32_t (*)(UniverseID containerid, const char* wareid);
33 | using GetContainerStockLimitOverrides = uint32_t (*)(
34 | UIWareInfo* result, uint32_t resultlen, UniverseID containerid);
35 | using GetContainerTradeRuleID = TradeRuleID (*)(
36 | UniverseID containerid, const char* ruletype, const char* wareid);
37 | using GetContainerWareConsumption = double (*)(
38 | UniverseID containerid, const char* wareid, bool ignorestate);
39 | using GetContainerWareIsBuyable = bool (*)(UniverseID containerid, const char* wareid);
40 | using GetContainerWareIsSellable = bool (*)(UniverseID containerid, const char* wareid);
41 | using GetContainerWareMaxProductionStorageForTime = int32_t (*)(
42 | UniverseID containerid, const char* wareid, double duration, bool ignoreoverrides);
43 | using GetContainerWareProduction = double (*)(
44 | UniverseID containerid, const char* wareid, bool ignorestate);
45 | using GetContainerWareReservations2 = uint32_t (*)(WareReservationInfo2* result,
46 | uint32_t resultlen, UniverseID containerid, bool includevirtual, bool includemission,
47 | bool includesupply);
48 | using GetContextByClass = UniverseID (*)(
49 | UniverseID componentid, const char* classname, bool includeself);
50 | using GetCreditsDueFromPlayerBuilds = int64_t (*)(void);
51 | using GetCreditsDueFromPlayerTrades = int64_t (*)(void);
52 | using GetCurrentGameTime = double (*)(void);
53 | using GetCurrentUTCDataTime = int64_t (*)(void);
54 | using GetCurrentVentureInfo = UIVentureInfo (*)(UniverseID ventureplatformid);
55 | using GetCurrentVentureShips = uint32_t (*)(
56 | UniverseID* result, uint32_t resultlen, UniverseID ventureplatformid);
57 | using GetDockedShips = uint32_t (*)(UniverseID* result, uint32_t resultlen,
58 | UniverseID dockingbayorcontainerid, const char* factionid);
59 | using GetFightRuleInfo = bool (*)(FightRuleInfo* info, FightRuleID id);
60 | using GetFightRuleInfoCounts = FightRuleCounts (*)(FightRuleID id);
61 | using GetInstalledEngineMod = bool (*)(UniverseID objectid, UIEngineMod* enginemod);
62 | using GetInstalledGroupedWeaponMod = bool (*)(UniverseID defensibleid, UniverseID contextid,
63 | const char* group, UIWeaponMod* weaponmod);
64 | using GetInstalledShieldMod = bool (*)(UniverseID defensibleid, UniverseID contextid,
65 | const char* group, UIShieldMod* shieldmod);
66 | using GetInstalledShipMod2 = bool (*)(UniverseID shipid, UIShipMod2* shipmod);
67 | using GetInstalledWeaponMod = bool (*)(UniverseID weaponid, UIWeaponMod* weaponmod);
68 | using GetMappedInputName = const char* (*)(const char* functionkey);
69 | using GetMoneyLog = uint32_t (*)(MoneyLogEntry* result, size_t resultlen,
70 | UniverseID componentid, double starttime, double endtime);
71 | using GetNumAllBlacklists = uint32_t (*)(void);
72 | using GetNumAllEquipmentModProperties = uint32_t (*)(const char* equipmentmodclass);
73 | using GetNumAllFightRules = uint32_t (*)(void);
74 | using GetNumAllTradeRules = uint32_t (*)(void);
75 | using GetNumCargoTransportTypes = uint32_t (*)(UniverseID containerid, bool merge);
76 | using GetNumContainerStockLimitOverrides = uint32_t (*)(UniverseID containerid);
77 | using GetNumContainerWareReservations2 = uint32_t (*)(
78 | UniverseID containerid, bool includevirtual, bool includemission, bool includesupply);
79 | using GetNumDockedShips = uint32_t (*)(
80 | UniverseID dockingbayorcontainerid, const char* factionid);
81 | using GetNumTerraformingProjects = uint32_t (*)(UniverseID clusterid, bool useevents);
82 | using GetNumTransactionLog = uint32_t (*)(
83 | UniverseID componentid, double starttime, double endtime);
84 | using GetNumVenturePlatformDocks = uint32_t (*)(UniverseID ventureplatformid);
85 | using GetNumVenturePlatforms = uint32_t (*)(UniverseID defensibleid);
86 | using GetObjectIDCode = const char* (*)(UniverseID objectid);
87 | using GetObjectPositionInSector = UIPosRot (*)(UniverseID objectid);
88 | using GetPlayerCoverFaction = const char* (*)(void);
89 | using GetPlayerCurrentControlGroup = const char* (*)(void);
90 | using GetPlayerID = UniverseID (*)(void);
91 | using GetPlayerName = const char* (*)(void);
92 | using GetPlayerOccupiedShipID = UniverseID (*)(void);
93 | using GetTerraformingProjectBlockingProjects = uint32_t (*)(
94 | const char** result, uint32_t resultlen, UniverseID clusterid, const char* projectid);
95 | using GetTerraformingProjectConditions = uint32_t (*)(
96 | UITerraformingProjectCondition* result, uint32_t resultlen, UniverseID clusterid,
97 | const char* projectid);
98 | using GetTerraformingProjectEffects = uint32_t (*)(UITerraformingProjectEffect* result,
99 | uint32_t resultlen, UniverseID clusterid, const char* projectid);
100 | using GetTerraformingProjectPredecessorGroups = uint32_t (*)(
101 | UITerraformingProjectPredecessorGroup* result, uint32_t resultlen, UniverseID clusterid,
102 | const char* projectid);
103 | using GetTerraformingProjectPredecessors = uint32_t (*)(
104 | const char** result, uint32_t resultlen, UniverseID clusterid, const char* projectid);
105 | using GetTerraformingProjectRebatedResources = uint32_t (*)(
106 | UIWareInfo* result, uint32_t resultlen, UniverseID clusterid, const char* projectid);
107 | using GetTerraformingProjectRebates = uint32_t (*)(UITerraformingProjectRebate* result,
108 | uint32_t resultlen, UniverseID clusterid, const char* projectid);
109 | using GetTerraformingProjectRemovedProjects = uint32_t (*)(
110 | const char** result, uint32_t resultlen, UniverseID clusterid, const char* projectid);
111 | using GetTextHeight = float (*)(const char* const text, const char* const fontname,
112 | const float fontsize, const float wordwrapwidth);
113 | using GetTextWidth = float (*)(
114 | const char* const text, const char* const fontname, const float fontsize);
115 | using GetTransactionLog = uint32_t (*)(TransactionLogEntry* result, uint32_t resultlen,
116 | UniverseID componentid, double starttime, double endtime);
117 | using GetTopLevelContainer = UniverseID (*)(UniverseID componentid);
118 | using GetTradeRuleInfo = bool (*)(TradeRuleInfo* info, TradeRuleID id);
119 | using GetTradeRuleInfoCounts = TradeRuleCounts (*)(TradeRuleID id);
120 | using GetUIScale = float (*)(const bool scalewithresolution);
121 | using GetUpgradeSlotGroup = UpgradeGroup (*)(UniverseID destructibleid,
122 | const char* macroname, const char* upgradetypename, size_t slot);
123 | using GetVenturePlatformDocks = uint32_t (*)(
124 | UniverseID* result, uint32_t resultlen, UniverseID ventureplatformid);
125 | using GetVenturePlatforms = uint32_t (*)(
126 | UniverseID* result, uint32_t resultlen, UniverseID defensibleid);
127 | using GetWorkForceInfo = WorkForceInfo (*)(UniverseID containerid, const char* raceid);
128 | using HasContainerBuyLimitOverride = bool (*)(UniverseID containerid, const char* wareid);
129 | using HasContainerOwnTradeRule = bool (*)(
130 | UniverseID containerid, const char* ruletype, const char* wareid);
131 | using HasContainerSellLimitOverride = bool (*)(UniverseID containerid, const char* wareid);
132 | using IsComponentClass = bool (*)(UniverseID componentid, const char* classname);
133 | using IsComponentOperational = bool (*)(UniverseID componentid);
134 | using IsConversationActive = bool (*)(void);
135 | using IsConversationCancelling = bool (*)(void);
136 | using IsDemoVersion = bool (*)(void);
137 | using IsInfoUnlockedForPlayer = bool (*)(UniverseID componentid, const char* infostring);
138 | using IsGameOver = bool (*)(void);
139 | using IsNextStartAnimationSkipped = bool (*)(bool reset);
140 | using IsOnlineEnabled = bool (*)(void);
141 | using IsPlayerBlacklistDefault = bool (*)(
142 | BlacklistID id, const char* listtype, const char* defaultgroup);
143 | using IsPlayerFightRuleDefault = bool (*)(FightRuleID id, const char* listtype);
144 | using IsSetaActive = bool (*)();
145 | using IsStartmenu = bool (*)();
146 | using IsTerraformingProjectOngoing = bool (*)(UniverseID clusterid, const char* projectid);
147 | using IsVRMode = bool (*)(void);
148 | using IsWeaponModeCompatible = bool (*)(
149 | UniverseID weaponid, const char* macroname, const char* weaponmodeid);
150 | using ReleaseConstructionMapState = void (*)(void);
151 | using ReleaseDetachedSubordinateGroup = void (*)(UniverseID controllableid, int group);
152 | using RemoveTrackedMenu = void (*)(const char* menu);
153 | using RemoveTradeWare = void (*)(UniverseID containerid, const char* wareid);
154 | using SetBoxText = void (*)(const int boxtextid, const char* text);
155 | using SetBoxTextBoxColor = void (*)(const int boxtextid, Color color);
156 | using SetBoxTextColor = void (*)(const int boxtextid, Color color);
157 | using SetButtonActive = void (*)(const int buttonid, bool active);
158 | using SetButtonHighlightColor = void (*)(const int buttonid, Color color);
159 | using SetButtonIconColor = void (*)(const int buttonid, Color color);
160 | using SetButtonIcon2Color = void (*)(const int buttonid, Color color);
161 | using SetButtonIconID = void (*)(const int buttonid, const char* iconid);
162 | using SetButtonIcon2ID = void (*)(const int buttonid, const char* iconid);
163 | using SetButtonTextColor = void (*)(const int buttonid, Color color);
164 | using SetButtonText2 = void (*)(const int buttonid, const char* text);
165 | using SetButtonText2Color = void (*)(const int buttonid, Color color);
166 | using SetCheckBoxChecked2 = void (*)(const int checkboxid, bool checked, bool update);
167 | using SetCheckBoxColor = void (*)(const int checkboxid, Color color);
168 | using SetContainerBuyLimitOverride = void (*)(
169 | UniverseID containerid, const char* wareid, int32_t amount);
170 | using SetContainerSellLimitOverride = void (*)(
171 | UniverseID containerid, const char* wareid, int32_t amount);
172 | using SetContainerTradeRule = void (*)(UniverseID containerid, TradeRuleID id,
173 | const char* ruletype, const char* wareid, bool value);
174 | using SetContainerWareIsBuyable = void (*)(
175 | UniverseID containerid, const char* wareid, bool allowed);
176 | using SetContainerWareIsSellable = void (*)(
177 | UniverseID containerid, const char* wareid, bool allowed);
178 | using SetDropDownCurOption = void (*)(const int dropdownid, const char* id);
179 | using SetEditBoxActive = void (*)(const int editboxid, bool active);
180 | using SetEditBoxText = void (*)(const int editboxid, const char* text);
181 | using SetEditBoxTextHidden = void (*)(const int editboxid, bool hidden);
182 | using SetFlowChartEdgeColor = void (*)(const int flowchartedgeid, Color color);
183 | using SetFlowChartNodeCaptionText = void (*)(const int flowchartnodeid, const char* text);
184 | using SetFlowChartNodeCaptionTextColor = void (*)(const int flowchartnodeid, Color color);
185 | using SetFlowChartNodeCurValue = void (*)(const int flowchartnodeid, double value);
186 | using SetFlowchartNodeExpanded = void (*)(
187 | const int flowchartnodeid, const int frameid, bool expandedabove);
188 | using SetFlowChartNodeMaxValue = void (*)(const int flowchartnodeid, double value);
189 | using SetFlowChartNodeOutlineColor = void (*)(const int flowchartnodeid, Color color);
190 | using SetFlowChartNodeSlider1Value = void (*)(const int flowchartnodeid, double value);
191 | using SetFlowChartNodeSlider2Value = void (*)(const int flowchartnodeid, double value);
192 | using SetFlowChartNodeSliderStep = void (*)(const int flowchartnodeid, double step);
193 | using SetFlowChartNodeStatusBgIcon = void (*)(
194 | const int flowchartnodeid, const char* iconid);
195 | using SetFlowChartNodeStatusIcon = void (*)(const int flowchartnodeid, const char* iconid);
196 | using SetFlowChartNodeStatusIconMouseOverText = void (*)(
197 | const int flowchartnodeid, const char* mouseovertext);
198 | using SetFlowChartNodeStatusText = void (*)(const int flowchartnodeid, const char* text);
199 | using SetFlowChartNodeStatusColor = void (*)(const int flowchartnodeid, Color color);
200 | using SetIcon = void (*)(const int widgeticonid, const char* iconid);
201 | using SetIconColor = void (*)(const int widgeticonid, Color color);
202 | using SetIconText = void (*)(const int widgeticonid, const char* text);
203 | using SetIconText2 = void (*)(const int widgeticonid, const char* text);
204 | using SetMouseOverText = void (*)(int widgetid, const char* text);
205 | using SetShieldHullBarHullPercent = void (*)(const int shieldhullbarid, float hullpercent);
206 | using SetShieldHullBarShieldPercent = void (*)(
207 | const int shieldhullbarid, float shieldpercent);
208 | using SetSliderCellMaxSelectValue = void (*)(const int slidercellid, double value);
209 | using SetSliderCellMaxValue = void (*)(const int slidercellid, double value);
210 | using SetSubordinateGroupAssignment = void (*)(
211 | UniverseID controllableid, int group, const char* assignment);
212 | using SetSubordinateGroupProtectedLocation = void (*)(
213 | UniverseID controllableid, int group, UniverseID sectorid, UIPosRot offset);
214 | using SetStatusBarCurrentValue = void (*)(const int statusbarid, float value);
215 | using SetStatusBarMaxValue = void (*)(const int statusbarid, float value);
216 | using SetStatusBarStartValue = void (*)(const int statusbarid, float value);
217 | using SetTableNextConnectedTable = void (*)(const int tableid, const int nexttableid);
218 | using SetTablePreviousConnectedTable = void (*)(const int tableid, const int prevtableid);
219 | using SetTableNextHorizontalConnectedTable = void (*)(
220 | const int tableid, const int nexttableid);
221 | using SetTablePreviousHorizontalConnectedTable = void (*)(
222 | const int tableid, const int prevtableid);
223 | using SetWidgetViewScheduled = void (*)(bool scheduled);
224 | using SkipNextStartAnimation = void (*)(void);
225 | using TrackMenu = void (*)(const char* menu, bool fullscreen);
226 | }
--------------------------------------------------------------------------------
/X4_Rest_Reloaded/ffi/x4ffi/ffi_funcs_menu_playerinfo.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "ffi_typedef.h"
3 | #include "ffi_typedef_struct.h"
4 |
5 | // Regex to convert the lua definitions to c++ typedefs
6 | // \t(.+?)(([0-z])+?)\(
7 | // using $2 = $1(*)(
8 |
9 | namespace X4FFI {
10 |
11 | using AddPlayerAlert2 = void (*)(PlayerAlertInfo2 alert);
12 | using AreVenturesCompatible = bool (*)(void);
13 | using CreateBlacklist2 = BlacklistID (*)(BlacklistInfo2 info);
14 | using CreateFightRule = FightRuleID (*)(FightRuleInfo info);
15 | using CreateNPCFromPerson = UniverseID (*)(NPCSeed person, UniverseID controllableid);
16 | using CreateTradeRule = TradeRuleID (*)(TradeRuleInfo info);
17 | using DropInventory = bool (*)(UniverseID entityid, const char* lockboxid, UIWareAmount* wares, uint32_t numwares);
18 | using GenerateFactionRelationText = const char* (*)(const char* factionid);
19 | using GetAllFactionShips = uint32_t (*)(UniverseID* result, uint32_t resultlen, const char* factionid);
20 | using GetAllFactionStations = uint32_t (*)(UniverseID* result, uint32_t resultlen, const char* factionid);
21 | using GetAllTradeRules = uint32_t (*)(TradeRuleID* result, uint32_t resultlen);
22 | using GetAvailableClothingThemes = uint32_t (*)(UIClothingTheme* result, uint32_t resultlen);
23 | using GetAvailableEquipmentMods = uint32_t (*)(UIEquipmentMod* result, uint32_t resultlen);
24 | using GetAvailableLockboxes = uint32_t (*)(const char** result, uint32_t resultlen, UniverseID entityid);
25 | using GetAvailablePaintThemes = uint32_t (*)(UIPaintTheme* result, uint32_t resultlen);
26 | using GetComponentName = const char* (*)(UniverseID componentid);
27 | using GetContextByClass = UniverseID (*)(UniverseID componentid, const char* classname, bool includeself);
28 | using GetCurrentGameTime = double (*)(void);
29 | using GetCurrentPlayerLogo = UILogo (*)(void);
30 | using GetEntityCombinedSkill = int32_t (*)(UniverseID entityid, const char* role, const char* postid);
31 | using GetEntitySkillsForAssignment = uint32_t (*)(
32 | Skill2* result, UniverseID entityid, const char* role, const char* postid);
33 | using GetFactionDefaultWeaponMode = const char* (*)(const char* factionid);
34 | using GetLastPlayerControlledShipID = UniverseID (*)(void);
35 | using GetMessageInteractPosition = UIPosRot (*)(MessageID messageid);
36 | using GetMessages = uint32_t (*)(
37 | MessageInfo* result, uint32_t resultlen, size_t start, size_t count, const char* categoryname);
38 | using GetNotificationTypes = uint32_t (*)(UINotificationType* result, uint32_t resultlen);
39 | using GetNumAllFactionShips = uint32_t (*)(const char* factionid);
40 | using GetNumAllFactionStations = uint32_t (*)(const char* factionid);
41 | using GetNumAllRoles = uint32_t (*)(void);
42 | using GetNumAllTradeRules = uint32_t (*)(void);
43 | using GetNumAvailableClothingThemes = uint32_t (*)();
44 | using GetNumAvailableEquipmentMods = uint32_t (*)();
45 | using GetNumAvailableLockboxes = uint32_t (*)(UniverseID entityid);
46 | using GetNumAvailablePaintThemes = uint32_t (*)();
47 | using GetNumMessages = uint32_t (*)(const char* categoryname, bool);
48 | using GetNumNotificationTypes = uint32_t (*)(void);
49 | using GetNumPlayerAlerts = uint32_t (*)(void);
50 | using GetNumPlayerAlertSounds2 = uint32_t (*)(const char* tags);
51 | using GetNumPlayerBuildMethods = uint32_t (*)(void);
52 | using GetNumPlayerLogos = uint32_t (*)(bool includestandard, bool includecustom);
53 | using GetNumSkills = uint32_t (*)(void);
54 | using GetNumStationModules = uint32_t (*)(UniverseID stationid, bool includeconstructions, bool includewrecks);
55 | using GetNumTransactionLog = uint32_t (*)(UniverseID componentid, double starttime, double endtime);
56 | using GetPersonCombinedSkill = int32_t (*)(
57 | UniverseID controllableid, NPCSeed person, const char* role, const char* postid);
58 | using GetPersonName = const char* (*)(NPCSeed person, UniverseID controllableid);
59 | using GetPersonRoleName = const char* (*)(NPCSeed person, UniverseID controllableid);
60 | using GetPersonSkills3 = uint32_t (*)(
61 | SkillInfo* result, uint32_t resultlen, NPCSeed person, UniverseID controllableid);
62 | using GetPeople2 = uint32_t (*)(
63 | PeopleInfo* result, uint32_t resultlen, UniverseID controllableid, bool includearriving);
64 | using GetPlayerAlertCounts = uint32_t (*)(PlayerAlertCounts* result, uint32_t resultlen);
65 | using GetPlayerAlerts2 = uint32_t (*)(PlayerAlertInfo2* result, uint32_t resultlen);
66 | using GetPlayerAlertSounds2 = uint32_t (*)(SoundInfo* result, uint32_t resultlen, const char* tags);
67 | using GetPlayerBuildMethod = const char* (*)(void);
68 | using GetPlayerBuildMethods = uint32_t (*)(ProductionMethodInfo* result, uint32_t resultlen);
69 | using GetPlayerClothingTheme = const char* (*)(void);
70 | using GetPlayerFactionName = const char* (*)(bool userawname);
71 | using GetPlayerGlobalLoadoutLevel = float (*)(void);
72 | using GetPlayerID = UniverseID (*)(void);
73 | using GetPlayerLogos = uint32_t (*)(UILogo* result, uint32_t resultlen, bool includestandard, bool includecustom);
74 | using GetPlayerPaintTheme = const char* (*)(void);
75 | using GetPlayerName = const char* (*)(void);
76 | using GetPlayerOccupiedShipID = UniverseID (*)(void);
77 | using GetPlayerGlobalTradeLoopCargoReservationSetting = bool (*)(void);
78 | using GetPlayerZoneID = UniverseID (*)(void);
79 | using GetPurposeName = const char* (*)(const char* purposeid);
80 | using GetRelationRangeUIMaxValue = int32_t (*)(const char* relationrangeid);
81 | using GetRoleTierNPCs = uint32_t (*)(
82 | NPCSeed* result, uint32_t resultlen, UniverseID controllableid, const char* role, int32_t skilllevel);
83 | using GetRoleTiers = uint32_t (*)(
84 | RoleTierData* result, uint32_t resultlen, UniverseID controllableid, const char* role);
85 | using GetSupplyBudget = int64_t (*)(UniverseID containerid);
86 | using GetStationModules = uint32_t (*)(
87 | UniverseID* result, uint32_t resultlen, UniverseID stationid, bool includeconstructions, bool includewrecks);
88 | using GetTextHeight = float (*)(
89 | const char* const text, const char* const fontname, const float fontsize, const float wordwrapwidth);
90 | using GetTradeRuleInfo = bool (*)(TradeRuleInfo* info, TradeRuleID id);
91 | using GetTradeRuleInfoCounts = TradeRuleCounts (*)(TradeRuleID id);
92 | using GetTradeWareBudget = int64_t (*)(UniverseID containerid);
93 | using HasPersonArrived = bool (*)(UniverseID controllableid, NPCSeed person);
94 | using IsComponentClass = bool (*)(UniverseID componentid, const char* classname);
95 | using IsComponentOperational = bool (*)(UniverseID componentid);
96 | using IsMouseEmulationActive = bool (*)(void);
97 | using IsPersonTransferScheduled = bool (*)(UniverseID controllableid, NPCSeed person);
98 | using IsPlayerTradeRuleDefault = bool (*)(TradeRuleID id, const char* ruletype);
99 | using IsShipAtExternalDock = bool (*)(UniverseID shipid);
100 | using IsUnit = bool (*)(UniverseID controllableid);
101 | using MutePlayerAlert = void (*)(size_t index);
102 | using ReadAllInventoryWares = void (*)(void);
103 | using ReadInventoryWare = void (*)(const char* wareid);
104 | using ReleasePersonFromCrewTransfer = void (*)(UniverseID controllableid, NPCSeed person);
105 | using RemoveBlacklist = void (*)(BlacklistID id);
106 | using RemoveFightRule = void (*)(FightRuleID id);
107 | using RemovePerson = void (*)(UniverseID controllableid, NPCSeed person);
108 | using RemovePlayerAlert = void (*)(size_t index);
109 | using RemoveTradeRule = void (*)(TradeRuleID id);
110 | using SetEditBoxText = void (*)(const int editboxid, const char* text);
111 | using SetFactionBuildMethod = void (*)(const char* factionid, const char* buildmethodid);
112 | using SetFactionRelationToPlayerFaction = void (*)(const char* factionid, const char* reasonid, float boostvalue);
113 | using SetFactionDefaultWeaponMode = void (*)(const char* factionid, const char* weaponmode);
114 | using SetGuidance = void (*)(UniverseID componentid, UIPosRot offset);
115 | using SetMessageRead = void (*)(MessageID messageid, const char* categoryname);
116 | using SetNotificationTypeEnabled = void (*)(const char* id, bool value);
117 | using SetPlayerBlacklistDefault = void (*)(
118 | BlacklistID id, const char* listtype, const char* defaultgroup, bool value);
119 | using SetPlayerClothingTheme = void (*)(const char* theme);
120 | using SetPlayerFactionName = void (*)(const char* name);
121 | using SetPlayerFightRuleDefault = void (*)(FightRuleID id, const char* listtype, bool value);
122 | using SetPlayerGlobalLoadoutLevel = void (*)(float value);
123 | using SetPlayerIllegalWare = void (*)(const char* wareid, bool illegal);
124 | using SetPlayerLogo = void (*)(UILogo logo);
125 | using SetPlayerPaintTheme = void (*)(const char* theme);
126 | using SetPlayerShipsWaitForPlayer = void (*)(bool value);
127 | using SetPlayerTaxiWaitsForPlayer = void (*)(bool value);
128 | using SetPlayerTradeLoopCargoReservationSetting = void (*)(bool value);
129 | using SetPlayerTradeRuleDefault = void (*)(TradeRuleID id, const char* ruletype, bool value);
130 | using ShouldPlayerShipsWaitForPlayer = bool (*)(void);
131 | using ShouldPlayerTaxiWaitForPlayer = bool (*)(void);
132 | using SignalObjectWithNPCSeed = void (*)(
133 | UniverseID objecttosignalid, const char* param, NPCSeed person, UniverseID controllableid);
134 | using UnmutePlayerAlert = void (*)(size_t index, bool silent);
135 | using UpdateBlacklist2 = void (*)(BlacklistInfo2 info);
136 | using UpdateFightRule = void (*)(FightRuleInfo info);
137 | using UpdatePlayerAlert2 = void (*)(PlayerAlertInfo2 uialert);
138 | using UpdateTradeRule = void (*)(TradeRuleInfo info);
139 |
140 | } // namespace X4FFI
--------------------------------------------------------------------------------
/X4_Rest_Reloaded/ffi/x4ffi/ffi_funcs_station_config.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "ffi_typedef.h"
3 | #include "ffi_typedef_struct.h"
4 |
5 | // Regex to convert the lua definitions to c++ typedefs
6 | // \t(.+?)(([0-z])+?)\(
7 | // using $2 = $1(*)(
8 |
9 | namespace X4FFI {
10 | using AddFloatingSequenceToConstructionPlan = void (*)(UniverseID holomapid);
11 | using AddCopyToConstructionMap = void (*)(
12 | UniverseID holomapid, size_t cp_idx, bool copysequence);
13 | using AddMacroToConstructionMap = void (*)(
14 | UniverseID holomapid, const char* macroname, bool startdragging);
15 | using AreConstructionPlanLoadoutsCompatible = bool (*)(const char* constructionplanid);
16 | using CanBuildLoadout = bool (*)(UniverseID containerid, UniverseID defensibleid,
17 | const char* macroname, const char* loadoutid);
18 | using CanOpenWebBrowser = bool (*)(void);
19 | using CheckConstructionPlanForMacros = bool (*)(
20 | const char* constructionplanid, const char** macroids, uint32_t nummacroids);
21 | using ClearBuildMapSelection = void (*)(UniverseID holomapid);
22 | using CompareMapConstructionSequenceWithPlanned = bool (*)(
23 | UniverseID holomapid, UniverseID defensibleid, bool usestoredplan);
24 | using ConvertInputString = const char* (*)(const char* text, const char* defaultvalue);
25 | using DeselectMacroForConstructionMap = void (*)(UniverseID holomapid);
26 | using DoesConstructionSequenceRequireBuilder = bool (*)(UniverseID containerid);
27 | using ExportMapConstructionPlan = void (*)(UniverseID holomapid, const char* filename,
28 | const char* id, bool overwrite, const char* name, const char* desc);
29 | using ForceBuildCompletion = void (*)(UniverseID containerid);
30 | using GenerateModuleLoadout = void (*)(UILoadout* result, UniverseID holomapid,
31 | size_t cp_idx, UniverseID defensibleid, float level);
32 | using GenerateModuleLoadoutCounts = void (*)(UILoadoutCounts* result, UniverseID holomapid,
33 | size_t cp_idx, UniverseID defensibleid, float level);
34 | using GetAssignedConstructionVessels = uint32_t (*)(
35 | UniverseID* result, uint32_t resultlen, UniverseID containerid);
36 | using GetBlueprints = uint32_t (*)(UIBlueprint* result, uint32_t resultlen, const char* set,
37 | const char* category, const char* macroname);
38 | using GetBuildMapConstructionPlan = size_t (*)(UniverseID holomapid,
39 | UniverseID defensibleid, bool usestoredplan, UIConstructionPlanEntry* result,
40 | uint32_t resultlen);
41 | using GetBuildProcessorEstimatedTimeLeft = double (*)(UniverseID buildprocessorid);
42 | using GetCargo = uint32_t (*)(
43 | UIWareInfo* result, uint32_t resultlen, UniverseID containerid, const char* tags);
44 | using GetConstructionPlanInvalidPatches = uint32_t (*)(
45 | InvalidPatchInfo* result, uint32_t resultlen, const char* constructionplanid);
46 | using GetConstructionPlans = uint32_t (*)(UIConstructionPlan* result, uint32_t resultlen);
47 | using GetConstructionMapItemLoadout2 = void (*)(UILoadout* result, UniverseID holomapid,
48 | size_t itemidx, UniverseID defensibleid, UniverseID moduleid);
49 | using GetConstructionMapItemLoadoutCounts2 = void (*)(UILoadoutCounts* result,
50 | UniverseID holomapid, size_t itemidx, UniverseID defensibleid, UniverseID moduleid);
51 | using GetConstructionMapVenturePlatform = size_t (*)(
52 | UniverseID holomapid, size_t venturedockidx);
53 | using GetContainerGlobalPriceFactor = float (*)(UniverseID containerid);
54 | using GetContainerTradeRuleID = TradeRuleID (*)(
55 | UniverseID containerid, const char* ruletype, const char* wareid);
56 | using GetContainerWareReservations2 = uint32_t (*)(WareReservationInfo2* result,
57 | uint32_t resultlen, UniverseID containerid, bool includevirtual, bool includemission,
58 | bool includesupply);
59 | using GetContextByClass = UniverseID (*)(
60 | UniverseID componentid, const char* classname, bool includeself);
61 | using GetCurrentBuildProgress = float (*)(UniverseID containerid);
62 | using GetCurrentLoadout = void (*)(
63 | UILoadout* result, UniverseID defensibleid, UniverseID moduleid);
64 | using GetCurrentLoadoutCounts = void (*)(
65 | UILoadoutCounts* result, UniverseID defensibleid, UniverseID moduleid);
66 | using GetDefensibleLoadoutLevel = float (*)(UniverseID defensibleid);
67 | using GetGameStartName = const char* (*)();
68 | using GetImportableConstructionPlans = uint32_t (*)(
69 | UIConstructionPlanInfo* result, uint32_t resultlen);
70 | using GetLoadout = void (*)(UILoadout* result, UniverseID defensibleid,
71 | const char* macroname, const char* loadoutid);
72 | using GetLoadoutCounts = uint32_t (*)(UILoadoutCounts* result, UniverseID defensibleid,
73 | const char* macroname, const char* loadoutid);
74 | using GetLoadoutInvalidPatches = uint32_t (*)(InvalidPatchInfo* result, uint32_t resultlen,
75 | UniverseID defensibleid, const char* macroname, const char* loadoutid);
76 | using GetLoadoutsInfo = uint32_t (*)(UILoadoutInfo* result, uint32_t resultlen,
77 | UniverseID componentid, const char* macroname);
78 | using GetMissingConstructionPlanBlueprints3 = const char* (*)(UniverseID containerid,
79 | UniverseID holomapid, const char* constructionplanid, bool useplanned);
80 | using GetNumAssignedConstructionVessels = uint32_t (*)(UniverseID containerid);
81 | using GetNumBlueprints = uint32_t (*)(
82 | const char* set, const char* category, const char* macroname);
83 | using GetNumBuildMapConstructionPlan = size_t (*)(UniverseID holomapid, bool usestoredplan);
84 | using GetNumCargo = uint32_t (*)(UniverseID containerid, const char* tags);
85 | using GetNumConstructionMapVenturePlatformDocks = uint32_t (*)(
86 | UniverseID holomapid, size_t ventureplatformidx);
87 | using GetNumConstructionPlans = uint32_t (*)(void);
88 | using GetNumContainerWareReservations2 = uint32_t (*)(
89 | UniverseID containerid, bool includevirtual, bool includemission, bool includesupply);
90 | using GetNumImportableConstructionPlans = uint32_t (*)();
91 | using GetNumLoadoutsInfo = uint32_t (*)(UniverseID componentid, const char* macroname);
92 | using GetNumPlannedLimitedModules = uint32_t (*)(const char* constructionplanid);
93 | using GetNumRemovedConstructionPlanModules2 = uint32_t (*)(UniverseID holomapid,
94 | UniverseID defensibleid, uint32_t* newIndex, bool usestoredplan,
95 | uint32_t* numChangedIndices, bool checkupgrades);
96 | using GetNumUpgradeGroupCompatibilities = uint32_t (*)(UniverseID destructibleid,
97 | const char* macroname, UniverseID contextid, const char* path, const char* group,
98 | const char* upgradetypename);
99 | using GetNumUpgradeGroups = uint32_t (*)(UniverseID destructibleid, const char* macroname);
100 | using GetNumUpgradeSlots = size_t (*)(
101 | UniverseID destructibleid, const char* macroname, const char* upgradetypename);
102 | using GetNumUsedLimitedModules = uint32_t (*)(UniverseID excludedstationid);
103 | using GetNumUsedLimitedModulesFromSubsequence = uint32_t (*)(
104 | UniverseID holomapid, size_t cp_idx);
105 | using GetNumWares = uint32_t (*)(
106 | const char* tags, bool research, const char* licenceownerid, const char* exclusiontags);
107 | using GetObjectIDCode = const char* (*)(UniverseID objectid);
108 | using GetPickedBuildMapEntry2 = bool (*)(UniverseID holomapid, UniverseID defensibleid,
109 | UIConstructionPlanEntry* result, bool requirecomponentid);
110 | using SelectPickedBuildMapEntry = void (*)(UniverseID holomapid);
111 | using GetPickedMapMacroSlot = bool (*)(UniverseID holomapid, UniverseID defensibleid,
112 | UniverseID moduleid, const char* macroname, bool ismodule, UILoadoutSlot* result);
113 | using GetPlannedLimitedModules = uint32_t (*)(
114 | UIMacroCount* result, uint32_t resultlen, const char* constructionplanid);
115 | using GetRemovedConstructionPlanModules2 = uint32_t (*)(UniverseID* result,
116 | uint32_t resultlen, uint32_t* changedIndices, uint32_t* numChangedIndices);
117 | using GetSelectedBuildMapEntry = size_t (*)(UniverseID holomapid);
118 | using GetUpgradeGroupCompatibilities = uint32_t (*)(EquipmentCompatibilityInfo* result,
119 | uint32_t resultlen, UniverseID destructibleid, const char* macroname,
120 | UniverseID contextid, const char* path, const char* group, const char* upgradetypename);
121 | using GetUpgradeGroupInfo = UpgradeGroupInfo (*)(UniverseID destructibleid,
122 | const char* macroname, const char* path, const char* group,
123 | const char* upgradetypename);
124 | using GetUpgradeGroups = uint32_t (*)(UpgradeGroup* result, uint32_t resultlen,
125 | UniverseID destructibleid, const char* macroname);
126 | using GetUpgradeSlotCurrentMacro = const char* (*)(UniverseID objectid, UniverseID moduleid,
127 | const char* upgradetypename, size_t slot);
128 | using GetUpgradeSlotGroup = UpgradeGroup (*)(UniverseID destructibleid,
129 | const char* macroname, const char* upgradetypename, size_t slot);
130 | using GetUsedLimitedModules = uint32_t (*)(
131 | UIMacroCount* result, uint32_t resultlen, UniverseID excludedstationid);
132 | using GetUsedLimitedModulesFromSubsequence = uint32_t (*)(
133 | UIMacroCount* result, uint32_t resultlen, UniverseID holomapid, size_t cp_idx);
134 | using GetWares = uint32_t (*)(const char** result, uint32_t resultlen, const char* tags,
135 | bool research, const char* licenceownerid, const char* exclusiontags);
136 | using GetWorkForceInfo = WorkForceInfo (*)(UniverseID containerid, const char* raceid);
137 | using HasContainerOwnTradeRule = bool (*)(
138 | UniverseID containerid, const char* ruletype, const char* wareid);
139 | using ImportMapConstructionPlan = void (*)(const char* filename, const char* id);
140 | using IsBuildWaitingForSecondaryComponentResources = bool (*)(UniverseID containerid);
141 | using IsConstructionPlanValid = bool (*)(
142 | const char* constructionplanid, uint32_t* numinvalidpatches);
143 | using IsLoadoutCompatible = bool (*)(const char* macroname, const char* loadoutid);
144 | using IsLoadoutValid = bool (*)(UniverseID defensibleid, const char* macroname,
145 | const char* loadoutid, uint32_t* numinvalidpatches);
146 | using IsIconValid = bool (*)(const char* iconid);
147 | using IsMasterVersion = bool (*)(void);
148 | using IsNextStartAnimationSkipped = bool (*)(bool reset);
149 | using IsPlayerTradeRuleDefault = bool (*)(TradeRuleID id, const char* ruletype);
150 | using IsUpgradeGroupMacroCompatible = bool (*)(UniverseID destructibleid,
151 | const char* macroname, const char* path, const char* group, const char* upgradetypename,
152 | const char* upgrademacroname);
153 | using IsUpgradeMacroCompatible = bool (*)(UniverseID objectid, UniverseID moduleid,
154 | const char* macroname, bool ismodule, const char* upgradetypename, size_t slot,
155 | const char* upgrademacroname);
156 | using IsVentureVersion = bool (*)(void);
157 | using OpenWebBrowser = void (*)(const char* url);
158 | using ReleaseConstructionMapState = void (*)(void);
159 | using RemoveConstructionPlan = bool (*)(const char* source, const char* id);
160 | using RemoveFloatingSequenceFromConstructionPlan = void (*)(UniverseID holomapid);
161 | using RemoveItemFromConstructionMap2 = void (*)(
162 | UniverseID holomapid, size_t itemidx, bool removesequence);
163 | using RemoveOrder2 = bool (*)(UniverseID controllableid, size_t idx, bool playercancelled,
164 | bool checkonly, bool onlyimmediate);
165 | using ResetConstructionMapModuleRotation = void (*)(UniverseID holomapid, size_t cp_idx);
166 | using ResetMapPlayerRotation = void (*)(UniverseID holomapid);
167 | using SaveLoadout = void (*)(const char* macroname, UILoadout uiloadout, const char* source,
168 | const char* id, bool overwrite, const char* name, const char* desc);
169 | using SaveMapConstructionPlan = void (*)(UniverseID holomapid, const char* source,
170 | const char* id, bool overwrite, const char* name, const char* desc);
171 | using SelectBuildMapEntry = void (*)(UniverseID holomapid, size_t cp_idx);
172 | using SetConstructionMapBuildAngleStep = void (*)(UniverseID holomapid, float angle);
173 | using SetConstructionMapCollisionDetection = void (*)(UniverseID holomapid, bool value);
174 | using SetConstructionMapRenderSectorBackground = void (*)(UniverseID holomapid, bool value);
175 | using SetConstructionSequenceFromConstructionMap = void (*)(
176 | UniverseID containerid, UniverseID holomapid);
177 | using SetContainerGlobalPriceFactor = void (*)(UniverseID containerid, float value);
178 | using SetContainerTradeRule = void (*)(UniverseID containerid, TradeRuleID id,
179 | const char* ruletype, const char* wareid, bool value);
180 | using SetFocusMapConstructionPlanEntry = void (*)(
181 | UniverseID holomapid, size_t cp_idx, bool resetplayerpan);
182 | using SetMapPicking = void (*)(UniverseID holomapid, bool enable);
183 | using SetSelectedMapGroup = void (*)(UniverseID holomapid, UniverseID destructibleid,
184 | const char* macroname, const char* path, const char* group);
185 | using SetSelectedMapMacroSlot = void (*)(UniverseID holomapid, UniverseID defensibleid,
186 | UniverseID moduleid, const char* macroname, bool ismodule, const char* upgradetypename,
187 | size_t slot);
188 | using SetupConstructionSequenceModulesCache = void (*)(
189 | UniverseID holomapid, UniverseID defensibleid, bool enable);
190 | using ShowConstructionMap = void (*)(UniverseID holomapid, UniverseID stationid,
191 | const char* constructionplanid, bool restore);
192 | using ShowObjectConfigurationMap2 = void (*)(UniverseID holomapid, UniverseID defensibleid,
193 | UniverseID moduleid, const char* macroname, bool ismodule, UILoadout uiloadout,
194 | size_t cp_idx);
195 | using ShuffleMapConstructionPlan = bool (*)(UniverseID holomapid, bool checkonly);
196 | using StartPanMap = void (*)(UniverseID holomapid);
197 | using StartRotateMap = void (*)(UniverseID holomapid);
198 | using StopPanMap = bool (*)(UniverseID holomapid);
199 | using StopRotateMap = bool (*)(UniverseID holomapid);
200 | using StoreConstructionMapState = void (*)(UniverseID holomapid);
201 | using UpdateConstructionMapItemLoadout = void (*)(
202 | UniverseID holomapid, size_t itemidx, UniverseID defensibleid, UILoadout uiloadout);
203 | using UpdateObjectConfigurationMap = void (*)(UniverseID holomapid, UniverseID defensibleid,
204 | UniverseID moduleid, const char* macroname, bool ismodule, UILoadout uiloadout);
205 | using ZoomMap = void (*)(UniverseID holomapid, float zoomstep);
206 | using CanUndoConstructionMapChange = bool (*)(UniverseID holomapid);
207 | using UndoConstructionMapChange = void (*)(UniverseID holomapid);
208 | using CanRedoConstructionMapChange = bool (*)(UniverseID holomapid);
209 | using RedoConstructionMapChange = void (*)(UniverseID holomapid);
210 |
211 | using PrepareBuildSequenceResources2 = uint32_t (*)(
212 | UniverseID holomapid, UniverseID stationid, bool useplanned);
213 | using GetBuildSequenceResources = uint32_t (*)(UIWareInfo* result, uint32_t resultlen);
214 | using GetNumModuleRecycledResources = uint32_t (*)(UniverseID moduleid);
215 | using GetModuleRecycledResources = uint32_t (*)(
216 | UIWareInfo* result, uint32_t resultlen, UniverseID moduleid);
217 | using GetNumModuleNeededResources = uint32_t (*)(UniverseID holomapid, size_t cp_idx);
218 | using GetModuleNeededResources = uint32_t (*)(
219 | UIWareInfo* result, uint32_t resultlen, UniverseID holomapid, size_t cp_idx);
220 | using SetContainerBuildMethod = void (*)(UniverseID containerid, const char* buildmethodid);
221 | }
--------------------------------------------------------------------------------
/X4_Rest_Reloaded/ffi/x4ffi/ffi_typedef.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 |
4 | namespace X4FFI {
5 |
6 | typedef uint64_t AIOrderID;
7 | typedef int32_t BlacklistID;
8 | typedef uint64_t BuildTaskID;
9 | typedef int32_t FightRuleID;
10 | typedef uint64_t MissionID;
11 | typedef uint64_t NPCSeed;
12 | typedef uint64_t TradeID;
13 | typedef int32_t TradeRuleID;
14 | typedef uint64_t UniverseID;
15 |
16 | typedef uint64_t MessageID;
17 |
18 |
19 | } // namespace X4FFI
20 |
--------------------------------------------------------------------------------
/X4_Rest_Reloaded/ffi/x4ffi/ffi_typedef_struct.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "ffi_typedef.h"
4 |
5 | #include
6 |
7 | namespace X4FFI {
8 |
9 | typedef struct {
10 | const char* name;
11 | uint32_t size;
12 | } Font;
13 |
14 | typedef struct {
15 | uint32_t red;
16 | uint32_t green;
17 | uint32_t blue;
18 | uint32_t alpha;
19 | } Color;
20 | typedef struct {
21 | int x;
22 | int y;
23 | } Coord2D;
24 | typedef struct {
25 | uint32_t width;
26 | uint32_t height;
27 | uint32_t xHotspot;
28 | uint32_t yHotspot;
29 | } CursorInfo;
30 | typedef struct {
31 | Color color;
32 | uint32_t width;
33 | uint32_t height;
34 | uint32_t x;
35 | uint32_t y;
36 | } DropDownIconInfo;
37 | typedef struct {
38 | const char* id;
39 | const char* iconid;
40 | const char* text;
41 | const char* text2;
42 | const char* mouseovertext;
43 | Color overrideColor;
44 | bool displayRemoveOption;
45 | bool active;
46 | bool hasOverrideColor;
47 | } DropDownOption;
48 | typedef struct {
49 | Color color;
50 | Font font;
51 | const char* alignment;
52 | uint32_t x;
53 | uint32_t y;
54 | const char* textOverride;
55 | } DropDownTextInfo;
56 | typedef struct {
57 | double x;
58 | double y;
59 | bool inactive;
60 | } GraphDataPoint2;
61 | typedef struct {
62 | uint32_t MarkerType;
63 | uint32_t MarkerSize;
64 | Color MarkerColor;
65 | uint32_t LineType;
66 | uint32_t LineWidth;
67 | Color LineColor;
68 | size_t NumData;
69 | bool Highlighted;
70 | const char* MouseOverText;
71 | } GraphDataRecord;
72 | typedef struct {
73 | size_t DataRecordIdx;
74 | size_t DataIdx;
75 | const char* IconID;
76 | const char* MouseOverText;
77 | } GraphIcon;
78 | typedef struct {
79 | const char* text;
80 | Font font;
81 | Color color;
82 | } GraphTextInfo;
83 | typedef struct {
84 | GraphTextInfo label;
85 | double startvalue;
86 | double endvalue;
87 | double granularity;
88 | double offset;
89 | bool grid;
90 | Color color;
91 | Color gridcolor;
92 | } GraphAxisInfo;
93 | typedef struct {
94 | const char* iconid;
95 | uint32_t x;
96 | uint32_t y;
97 | bool display;
98 | } HotkeyInfo;
99 | typedef struct {
100 | int x;
101 | int y;
102 | } ResolutionInfo;
103 | typedef struct {
104 | double min;
105 | double minSelect;
106 | double max;
107 | double maxSelect;
108 | double start;
109 | double step;
110 | double infinitevalue;
111 | uint32_t maxfactor;
112 | bool exceedmax;
113 | bool hidemaxvalue;
114 | bool righttoleft;
115 | bool fromcenter;
116 | bool readonly;
117 | bool useinfinitevalue;
118 | bool usetimeformat;
119 | } SliderCellDetails;
120 | typedef struct {
121 | uint32_t toprow;
122 | uint32_t selectedrow;
123 | uint32_t selectedcol;
124 | uint32_t shiftstart;
125 | uint32_t shiftend;
126 | } TableSelectionInfo;
127 | typedef struct {
128 | const char* text;
129 | uint32_t x;
130 | int32_t y;
131 | const char* alignment;
132 | Color color;
133 | Font font;
134 | } TextInfo;
135 | typedef struct {
136 | const char* iconid;
137 | Color color;
138 | uint32_t width;
139 | uint32_t height;
140 | int32_t rotationrate;
141 | uint32_t rotstart;
142 | float rotduration;
143 | float rotinterval;
144 | float initscale;
145 | float scaleduration;
146 | } UIFrameTextureInfo;
147 | typedef struct {
148 | const char* id;
149 | const char* text;
150 | uint32_t x;
151 | uint32_t y;
152 | uint32_t width;
153 | uint32_t height;
154 | bool highlightonly;
155 | bool usebackgroundspan;
156 | } UIOverlayInfo2;
157 |
158 | typedef struct {
159 | const char* id;
160 | uint32_t textid;
161 | uint32_t descriptionid;
162 | uint32_t value;
163 | uint32_t relevance;
164 | const char* ware;
165 | } SkillInfo;
166 |
167 | typedef struct {
168 | const char* macro;
169 | const char* ware;
170 | uint32_t amount;
171 | uint32_t capacity;
172 | } AmmoData;
173 | typedef struct {
174 | const char* id;
175 | const char* text;
176 | } BoardingBehaviour;
177 | typedef struct {
178 | const char* id;
179 | const char* text;
180 | } BoardingPhase;
181 | typedef struct {
182 | uint32_t approach;
183 | uint32_t insertion;
184 | } BoardingRiskThresholds;
185 | typedef struct {
186 | BuildTaskID id;
187 | UniverseID buildingcontainer;
188 | UniverseID component;
189 | const char* macro;
190 | const char* factionid;
191 | UniverseID buildercomponent;
192 | int64_t price;
193 | bool ismissingresources;
194 | uint32_t queueposition;
195 | } BuildTaskInfo;
196 | typedef struct {
197 | const char* newroleid;
198 | NPCSeed seed;
199 | uint32_t amount;
200 | } CrewTransferContainer;
201 | typedef struct {
202 | const char* id;
203 | const char* name;
204 | } ControlPostInfo;
205 | typedef struct {
206 | UniverseID entity;
207 | UniverseID personcontrollable;
208 | NPCSeed personseed;
209 | } GenericActor;
210 | typedef struct {
211 | const char* id;
212 | const char* name;
213 | const char* description;
214 | } ResponseInfo;
215 | typedef struct {
216 | const char* id;
217 | const char* name;
218 | const char* description;
219 | uint32_t numresponses;
220 | const char* defaultresponse;
221 | bool ask;
222 | } SignalInfo;
223 | typedef struct {
224 | const char* name;
225 | const char* transport;
226 | uint32_t spaceused;
227 | uint32_t capacity;
228 | } StorageInfo;
229 | typedef struct {
230 | float x;
231 | float y;
232 | float z;
233 | } Coord3D;
234 | typedef struct {
235 | float dps;
236 | uint32_t quadranttextid;
237 | } DPSData;
238 | typedef struct {
239 | const char* id;
240 | const char* name;
241 | bool possible;
242 | } DroneModeInfo;
243 | typedef struct {
244 | const char* factionID;
245 | const char* factionName;
246 | const char* factionIcon;
247 | } FactionDetails;
248 | typedef struct {
249 | const char* icon;
250 | const char* caption;
251 | } MissionBriefingIconInfo;
252 | typedef struct {
253 | const char* missionName;
254 | const char* missionDescription;
255 | int difficulty;
256 | int upkeepalertlevel;
257 | const char* threadType;
258 | const char* mainType;
259 | const char* subType;
260 | const char* subTypeName;
261 | const char* faction;
262 | int64_t reward;
263 | const char* rewardText;
264 | size_t numBriefingObjectives;
265 | int activeBriefingStep;
266 | const char* opposingFaction;
267 | const char* license;
268 | float timeLeft;
269 | double duration;
270 | bool abortable;
271 | bool hasObjective;
272 | UniverseID associatedComponent;
273 | UniverseID threadMissionID;
274 | } MissionDetails;
275 | typedef struct {
276 | const char* id;
277 | const char* name;
278 | } MissionGroupDetails;
279 | typedef struct {
280 | MissionID missionid;
281 | uint32_t amount;
282 | uint32_t numskills;
283 | SkillInfo* skills;
284 | } MissionNPCInfo;
285 | typedef struct {
286 | const char* text;
287 | const char* actiontext;
288 | const char* detailtext;
289 | int step;
290 | bool failed;
291 | bool completedoutofsequence;
292 | } MissionObjectiveStep3;
293 | typedef struct {
294 | uint32_t id;
295 | bool ispin;
296 | bool ishome;
297 | } MultiverseMapPickInfo;
298 | typedef struct {
299 | NPCSeed seed;
300 | const char* roleid;
301 | int32_t tierid;
302 | const char* name;
303 | int32_t combinedskill;
304 | } NPCInfo;
305 | typedef struct {
306 | const char* chapter;
307 | const char* onlineid;
308 | } OnlineMissionInfo;
309 | typedef struct {
310 | const char* id;
311 | const char* name;
312 | const char* icon;
313 | const char* description;
314 | const char* category;
315 | const char* categoryname;
316 | bool infinite;
317 | uint32_t requiredSkill;
318 | } OrderDefinition;
319 | typedef struct {
320 | size_t queueidx;
321 | const char* state;
322 | const char* statename;
323 | const char* orderdef;
324 | size_t actualparams;
325 | bool enabled;
326 | bool isinfinite;
327 | bool issyncpointreached;
328 | bool istemporder;
329 | } Order;
330 | typedef struct {
331 | size_t queueidx;
332 | const char* state;
333 | const char* statename;
334 | const char* orderdef;
335 | size_t actualparams;
336 | bool enabled;
337 | bool isinfinite;
338 | bool issyncpointreached;
339 | bool istemporder;
340 | bool isoverride;
341 | } Order2;
342 | typedef struct {
343 | uint32_t id;
344 | AIOrderID orderid;
345 | const char* orderdef;
346 | const char* message;
347 | double timestamp;
348 | bool wasdefaultorder;
349 | bool wasinloop;
350 | } OrderFailure;
351 | typedef struct {
352 | const char* id;
353 | const char* name;
354 | const char* desc;
355 | uint32_t amount;
356 | uint32_t numtiers;
357 | bool canhire;
358 | } PeopleInfo;
359 | typedef struct {
360 | const char* id;
361 | const char* name;
362 | } ProductionMethodInfo;
363 | typedef struct {
364 | const char* id;
365 | const char* name;
366 | const char* shortname;
367 | const char* description;
368 | const char* icon;
369 | } RaceInfo;
370 | typedef struct {
371 | const char* name;
372 | int32_t skilllevel;
373 | uint32_t amount;
374 | } RoleTierData;
375 | typedef struct {
376 | UniverseID context;
377 | const char* group;
378 | UniverseID component;
379 | } ShieldGroup;
380 | typedef struct {
381 | uint32_t textid;
382 | uint32_t descriptionid;
383 | uint32_t value;
384 | uint32_t relevance;
385 | } Skill2;
386 | typedef struct {
387 | UniverseID softtargetID;
388 | const char* softtargetConnectionName;
389 | } SofttargetDetails;
390 | typedef struct {
391 | const char* max;
392 | const char* current;
393 | } SoftwareSlot;
394 | typedef struct {
395 | UniverseID controllableid;
396 | int group;
397 | } SubordinateGroup;
398 | typedef struct {
399 | uint32_t id;
400 | UniverseID owningcontrollable;
401 | size_t owningorderidx;
402 | bool reached;
403 | } SyncPointInfo2;
404 | typedef struct {
405 | const char* reason;
406 | NPCSeed person;
407 | NPCSeed partnerperson;
408 | } UICrewExchangeResult;
409 | typedef struct {
410 | const char* shape;
411 | const char* name;
412 | uint32_t requiredSkill;
413 | float radius;
414 | bool rollMembers;
415 | bool rollFormation;
416 | size_t maxShipsPerLine;
417 | } UIFormationInfo;
418 | typedef struct {
419 | const char* file;
420 | const char* icon;
421 | bool ispersonal;
422 | } UILogo;
423 | typedef struct {
424 | const char* icon;
425 | Color color;
426 | uint32_t volume_s;
427 | uint32_t volume_m;
428 | uint32_t volume_l;
429 | } UIMapTradeVolumeParameter;
430 | typedef struct {
431 | const char* id;
432 | const char* name;
433 | } UIModuleSet;
434 | typedef struct {
435 | const float x;
436 | const float y;
437 | const float z;
438 | const float yaw;
439 | const float pitch;
440 | const float roll;
441 | } UIPosRot;
442 | typedef struct {
443 | const char* wareid;
444 | uint32_t amount;
445 | } UIWareAmount;
446 | typedef struct {
447 | bool primary;
448 | uint32_t idx;
449 | } UIWeaponGroup;
450 | typedef struct {
451 | UniverseID contextid;
452 | const char* path;
453 | const char* group;
454 | } UpgradeGroup2;
455 | typedef struct {
456 | UniverseID currentcomponent;
457 | const char* currentmacro;
458 | const char* slotsize;
459 | uint32_t count;
460 | uint32_t operational;
461 | uint32_t total;
462 | } UpgradeGroupInfo;
463 | typedef struct {
464 | const char* id;
465 | const char* icon;
466 | const char* factoryname;
467 | const char* factorydesc;
468 | const char* factorymapicon;
469 | const char* factoryhudicon;
470 | uint32_t tier;
471 | } WareGroupInfo;
472 | typedef struct {
473 | UniverseID reserverid;
474 | const char* ware;
475 | uint32_t amount;
476 | bool isbuyreservation;
477 | double eta;
478 | TradeID tradedealid;
479 | MissionID missionid;
480 | bool isvirtual;
481 | bool issupply;
482 | } WareReservationInfo2;
483 | typedef struct {
484 | const char* ware;
485 | int32_t current;
486 | int32_t max;
487 | } WareYield;
488 | typedef struct {
489 | const char* id;
490 | const char* name;
491 | bool active;
492 | } WeaponSystemInfo;
493 | typedef struct {
494 | uint32_t current;
495 | uint32_t capacity;
496 | uint32_t optimal;
497 | uint32_t available;
498 | uint32_t maxavailable;
499 | double timeuntilnextupdate;
500 | } WorkForceInfo;
501 | typedef struct {
502 | const char* wareid;
503 | int32_t amount;
504 | } YieldInfo;
505 |
506 | typedef struct {
507 | UIPosRot offset;
508 | float cameradistance;
509 | } HoloMapState;
510 | typedef struct {
511 | UniverseID target;
512 | UIWareAmount* wares;
513 | uint32_t numwares;
514 | } MissionWareDeliveryInfo;
515 | typedef struct {
516 | size_t idx;
517 | const char* macroid;
518 | UniverseID componentid;
519 | UIPosRot offset;
520 | const char* connectionid;
521 | size_t predecessoridx;
522 | const char* predecessorconnectionid;
523 | bool isfixed;
524 | } UIConstructionPlanEntry;
525 | typedef struct {
526 | const char* objectiveText;
527 | float timeout;
528 | const char* progressname;
529 | uint32_t curProgress;
530 | uint32_t maxProgress;
531 | size_t numTargets;
532 | } MissionObjective2;
533 |
534 | typedef struct {
535 | const char* path;
536 | const char* group;
537 | } UpgradeGroup;
538 |
539 | typedef struct {
540 | size_t index;
541 | double interval;
542 | bool repeats;
543 | bool muted;
544 | uint32_t numspaces;
545 | UniverseID* spaceids;
546 | const char* objectclass;
547 | const char* objectpurpose;
548 | const char* objectidcode;
549 | const char* objectowner;
550 | const char* name;
551 | const char* message;
552 | const char* soundid;
553 | } PlayerAlertInfo2;
554 |
555 | typedef struct {
556 | uint32_t id;
557 | const char* type;
558 | const char* name;
559 | bool usemacrowhitelist;
560 | uint32_t nummacros;
561 | const char** macros;
562 | bool usefactionwhitelist;
563 | uint32_t numfactions;
564 | const char** factions;
565 | const char* relation;
566 | bool hazardous;
567 | } BlacklistInfo2;
568 |
569 | typedef struct {
570 | const char* factionid;
571 | const char* civiliansetting;
572 | const char* militarysetting;
573 | } UIFightRuleSetting;
574 |
575 | typedef struct {
576 | FightRuleID id;
577 | const char* name;
578 | uint32_t numfactions;
579 | UIFightRuleSetting* factions;
580 | } FightRuleInfo;
581 |
582 | typedef struct {
583 | uint32_t id;
584 | const char* name;
585 | uint32_t numfactions;
586 | const char** factions;
587 | bool iswhitelist;
588 | } TradeRuleInfo;
589 |
590 | typedef struct {
591 | const char* ID;
592 | const char* Name;
593 | const char* RawName;
594 | } UIClothingTheme;
595 |
596 | typedef struct {
597 | const char* Name;
598 | const char* RawName;
599 | const char* Ware;
600 | uint32_t Quality;
601 | } UIEquipmentMod;
602 |
603 | typedef struct {
604 | const char* ID;
605 | const char* Name;
606 | const char* RawName;
607 | const char* Icon;
608 | } UIPaintTheme;
609 |
610 | typedef struct {
611 | MessageID id;
612 | double time;
613 | const char* category;
614 | const char* title;
615 | const char* text;
616 | const char* source;
617 | UniverseID sourcecomponent;
618 | const char* interaction;
619 | UniverseID interactioncomponent;
620 | const char* interactiontext;
621 | const char* interactionshorttext;
622 | const char* cutscenekey;
623 | const char* entityname;
624 | const char* factionname;
625 | int64_t money;
626 | int64_t bonus;
627 | bool highlighted;
628 | bool isread;
629 | } MessageInfo;
630 |
631 | typedef struct {
632 | const char* id;
633 | const char* name;
634 | const char* desc;
635 | const char* category;
636 | bool enabled;
637 | } UINotificationType;
638 |
639 | typedef struct {
640 | uint32_t numspaces;
641 | } PlayerAlertCounts;
642 |
643 | typedef struct {
644 | const char* id;
645 | const char* name;
646 | } SoundInfo;
647 |
648 | typedef struct {
649 | uint32_t numfactions;
650 | } TradeRuleCounts;
651 |
652 | typedef struct {
653 | uint32_t nummacros;
654 | uint32_t numfactions;
655 | } BlacklistCounts;
656 |
657 | typedef struct {
658 | uint32_t numfactions;
659 | } FightRuleCounts;
660 |
661 | typedef struct {
662 | const char* id;
663 | const char* name;
664 | const char* description;
665 | const char* propdatatype;
666 | float basevalue;
667 | bool poseffect;
668 | } EquipmentModPropertyInfo;
669 |
670 | typedef struct {
671 | const char* Name;
672 | const char* RawName;
673 | const char* Ware;
674 | uint32_t Quality;
675 | const char* PropertyType;
676 | float DamageFactor;
677 | float CoolingFactor;
678 | float ReloadFactor;
679 | float SpeedFactor;
680 | float LifeTimeFactor;
681 | float MiningFactor;
682 | float StickTimeFactor;
683 | float ChargeTimeFactor;
684 | float BeamLengthFactor;
685 | uint32_t AddedAmount;
686 | float RotationSpeedFactor;
687 | float SurfaceElementFactor;
688 | } UIWeaponMod;
689 |
690 | typedef struct {
691 | double time;
692 | int64_t money;
693 | int64_t entryid;
694 | } MoneyLogEntry;
695 |
696 | typedef struct {
697 | const char* name;
698 | const char* rawname;
699 | const char* icon;
700 | const char* rewardicon;
701 | int64_t remainingtime;
702 | uint32_t numships;
703 | } UIVentureInfo;
704 |
705 | typedef struct {
706 | const char* ware;
707 | const char* macro;
708 | int amount;
709 | } UIWareInfo;
710 |
711 | typedef struct {
712 | const char* Name;
713 | const char* RawName;
714 | const char* Ware;
715 | uint32_t Quality;
716 | const char* PropertyType;
717 | float ForwardThrustFactor;
718 | float StrafeThrustFactor;
719 | float RotationThrustFactor;
720 | float BoostThrustFactor;
721 | float BoostDurationFactor;
722 | float BoostAttackTimeFactor;
723 | float BoostReleaseTimeFactor;
724 | float BoostChargeTimeFactor;
725 | float BoostRechargeTimeFactor;
726 | float TravelThrustFactor;
727 | float TravelStartThrustFactor;
728 | float TravelAttackTimeFactor;
729 | float TravelReleaseTimeFactor;
730 | float TravelChargeTimeFactor;
731 | } UIEngineMod;
732 |
733 | typedef struct {
734 | const char* Name;
735 | const char* RawName;
736 | const char* Ware;
737 | uint32_t Quality;
738 | const char* PropertyType;
739 | float CapacityFactor;
740 | float RechargeDelayFactor;
741 | float RechargeRateFactor;
742 | } UIShieldMod;
743 |
744 | typedef struct {
745 | double time;
746 | int64_t money;
747 | int64_t entryid;
748 | const char* eventtype;
749 | const char* eventtypename;
750 | UniverseID partnerid;
751 | const char* partnername;
752 | const char* partneridcode;
753 | int64_t tradeentryid;
754 | const char* tradeeventtype;
755 | const char* tradeeventtypename;
756 | UniverseID buyerid;
757 | UniverseID sellerid;
758 | const char* ware;
759 | uint32_t amount;
760 | int64_t price;
761 | bool complete;
762 | } TransactionLogEntry;
763 |
764 | typedef struct {
765 | const char* Name;
766 | const char* RawName;
767 | const char* Ware;
768 | uint32_t Quality;
769 | const char* PropertyType;
770 | float MassFactor;
771 | float DragFactor;
772 | float MaxHullFactor;
773 | float RadarRangeFactor;
774 | uint32_t AddedUnitCapacity;
775 | uint32_t AddedMissileCapacity;
776 | uint32_t AddedCountermeasureCapacity;
777 | uint32_t AddedDeployableCapacity;
778 | float RadarCloakFactor;
779 | float RegionDamageProtection;
780 | float HideCargoChance;
781 | } UIShipMod2;
782 |
783 | typedef struct {
784 | const char* stat;
785 | uint32_t min;
786 | uint32_t max;
787 | uint64_t minvalue;
788 | uint64_t maxvalue;
789 | bool issatisfied;
790 | } UITerraformingProjectCondition;
791 | typedef struct {
792 | const char* text;
793 | const char* stat;
794 | int32_t change;
795 | uint64_t value;
796 | uint64_t minvalue;
797 | uint64_t maxvalue;
798 | bool onfail;
799 | bool issideeffect;
800 | uint32_t chance;
801 | uint32_t setbackpercent;
802 | bool isbeneficial;
803 | } UITerraformingProjectEffect;
804 | typedef struct {
805 | const char* id;
806 | const char* name;
807 | } UITerraformingProjectGroup;
808 | typedef struct {
809 | const char* id;
810 | bool anyproject;
811 | } UITerraformingProjectPredecessorGroup;
812 | typedef struct {
813 | const char* ware;
814 | const char* waregroupname;
815 | uint32_t value;
816 | } UITerraformingProjectRebate;
817 |
818 | typedef struct {
819 | const char* macro;
820 | uint32_t amount;
821 | bool optional;
822 | } UILoadoutAmmoData;
823 | typedef struct {
824 | const char* macro;
825 | const char* path;
826 | const char* group;
827 | uint32_t count;
828 | bool optional;
829 | } UILoadoutGroupData;
830 | typedef struct {
831 | const char* macro;
832 | const char* upgradetypename;
833 | size_t slot;
834 | bool optional;
835 | } UILoadoutMacroData;
836 | typedef struct {
837 | const char* ware;
838 | } UILoadoutSoftwareData;
839 | typedef struct {
840 | const char* macro;
841 | bool optional;
842 | } UILoadoutVirtualMacroData;
843 | typedef struct {
844 | UILoadoutMacroData* weapons;
845 | uint32_t numweapons;
846 | UILoadoutMacroData* turrets;
847 | uint32_t numturrets;
848 | UILoadoutMacroData* shields;
849 | uint32_t numshields;
850 | UILoadoutMacroData* engines;
851 | uint32_t numengines;
852 | UILoadoutGroupData* turretgroups;
853 | uint32_t numturretgroups;
854 | UILoadoutGroupData* shieldgroups;
855 | uint32_t numshieldgroups;
856 | UILoadoutAmmoData* ammo;
857 | uint32_t numammo;
858 | UILoadoutAmmoData* units;
859 | uint32_t numunits;
860 | UILoadoutSoftwareData* software;
861 | uint32_t numsoftware;
862 | UILoadoutVirtualMacroData thruster;
863 | } UILoadout;
864 | typedef struct {
865 | uint32_t numweapons;
866 | uint32_t numturrets;
867 | uint32_t numshields;
868 | uint32_t numengines;
869 | uint32_t numturretgroups;
870 | uint32_t numshieldgroups;
871 | uint32_t numammo;
872 | uint32_t numunits;
873 | uint32_t numsoftware;
874 | } UILoadoutCounts;
875 | typedef struct {
876 | const char* id;
877 | const char* name;
878 | const char* iconid;
879 | bool deleteable;
880 | } UILoadoutInfo;
881 | typedef struct {
882 | const char* upgradetype;
883 | size_t slot;
884 | } UILoadoutSlot;
885 |
886 |
887 | typedef struct {
888 | const char* macro;
889 | const char* ware;
890 | const char* productionmethodid;
891 | } UIBlueprint;
892 |
893 | typedef struct {
894 | const char* id;
895 | const char* name;
896 | int32_t state;
897 | const char* requiredversion;
898 | const char* installedversion;
899 | } InvalidPatchInfo;
900 |
901 | typedef struct {
902 | const char* filename;
903 | const char* name;
904 | const char* id;
905 | } UIConstructionPlanInfo;
906 |
907 | typedef struct {
908 | const char* name;
909 | const char* id;
910 | const char* source;
911 | bool deleteable;
912 | } UIConstructionPlan;
913 |
914 | typedef struct {
915 | const char* macro;
916 | uint32_t amount;
917 | } UIMacroCount;
918 |
919 | typedef struct {
920 | const char* tag;
921 | const char* name;
922 | } EquipmentCompatibilityInfo;
923 |
924 | } // namespace X4FFI
--------------------------------------------------------------------------------
/X4_Rest_Reloaded/httpserver/HttpServer.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2021-2023 Peter Repukat - FlatspotSoftware
3 |
4 | Use of this source code is governed by the MIT
5 | license that can be found in the LICENSE file or at
6 | https://opensource.org/licenses/MIT.
7 | */
8 |
9 | #include "HttpServer.h"
10 | HttpServer::HttpServer(FFIInvoke& ffi_invoke) : ffi_invoke_(ffi_invoke) {}
11 |
12 | std::string HttpServer::ToString(Method m) {
13 | switch (m) {
14 | case POST:
15 | return "POST";
16 | case PATCH:
17 | return "PATCH";
18 | case PUT:
19 | return "PUT";
20 | default:
21 | return "GET";
22 | }
23 | }
24 |
25 | void HttpServer::AddEndpoint(const Endpoint&& e) { endpoints_.push_back(e); }
26 |
27 | void HttpServer::run(int port) {
28 |
29 | server_.set_default_headers(httplib::Headers{{"Access-Control-Allow-Origin", "*"}});
30 |
31 | server_.Get("/", [ this ](const httplib::Request& req, httplib::Response& res) {
32 | auto content_json = nlohmann::json{{"endpoints", nlohmann::json::array()}};
33 |
34 | for (const auto& e : endpoints_) {
35 | content_json[ "endpoints" ].push_back(nlohmann::json{
36 | {"path", e.path},
37 | {"method", ToString(e.method)},
38 | {"response", e.response_hint},
39 | {"payload", e.payload_hint},
40 | });
41 | }
42 |
43 | content_json[ "endpoints" ].push_back(
44 | nlohmann::json{{"path", "/stop"}, {"method", "POST"}});
45 |
46 | res.set_content(content_json.dump(4), "application/json");
47 | res.status = 200;
48 | });
49 |
50 | for (const auto& e : endpoints_) {
51 | const auto fn =
52 | ([ this, &e ]() -> httplib::Server& (httplib::Server::*)(const std::string&,
53 | httplib::Server::Handler) {
54 | switch (e.method) {
55 | case POST:
56 | return &httplib::Server::Post;
57 | case PUT:
58 | return &httplib::Server::Put;
59 | case PATCH:
60 | return &httplib::Server::Patch;
61 | default:
62 | return &httplib::Server::Get;
63 | }
64 | })();
65 |
66 | (server_.*fn)(
67 | e.path, [ this, &e ](const httplib::Request& req, httplib::Response& res) {
68 | res.status = 0;
69 | res.content_length_ = 0;
70 | try {
71 | e.handler(req, res);
72 | }
73 | catch (std::exception& err) {
74 | // spdlog::error("Exception in http handler: {}", err.what());
75 | res.status = res.status == 0 ? 500 : res.status;
76 | if (res.content_length_ == 0) {
77 | res.set_content(
78 | nlohmann::json{
79 | {"code", res.status},
80 | {"name", "HandlerError"},
81 | {"message", err.what()},
82 | }
83 | .dump(),
84 | "application/json");
85 | }
86 | }
87 | catch (...) {
88 | res.status = 500;
89 | res.set_content(
90 | nlohmann::json{
91 | {"code", res.status},
92 | {"name", "Internal Server Error"},
93 | {"message", "Unknown Error"},
94 | }
95 | .dump(),
96 | "application/json");
97 | }
98 | if (res.status == 0) {
99 | res.status = e.method == Method::POST ? 201 : 200;
100 | }
101 | });
102 | }
103 |
104 | // --
105 | #ifdef _DEBUG
106 | server_.Post("/stop", [ & ](const httplib::Request& req, httplib::Response& res) {
107 | std::thread([ & ]() { server_.stop(); }).detach();
108 | res.set_content(nlohmann::json{{"ejected", true}}.dump(), "application/json");
109 | });
110 | #endif
111 | // somehow got bad request every other request without an extra thread o.O
112 | // (The server_ already runs in it's own separate thread by default...
113 | std::thread([ & ]() { server_.listen("0.0.0.0", port); }).join();
114 | }
--------------------------------------------------------------------------------
/X4_Rest_Reloaded/httpserver/HttpServer.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2021-2023 Peter Repukat - FlatspotSoftware
3 |
4 | Use of this source code is governed by the MIT
5 | license that can be found in the LICENSE file or at
6 | https://opensource.org/licenses/MIT.
7 | */
8 |
9 | #pragma once
10 | #include
11 | #include
12 | #include
13 |
14 | #define SET_CONTENT(content) res.set_content(nlohmann::json content.dump(), "application/json")
15 |
16 | #define HAN_FN [ & ](const httplib::Request& req, httplib::Response& res)
17 |
18 | #define SIMPLE_GET_HANDLER(FuncName) \
19 | { \
20 | std::string("/") + QUOTE(FuncName), HttpServer::Method::GET, HAN_FN { \
21 | const auto callResult = invoke(FuncName); \
22 | SET_CONTENT((callResult)); \
23 | } \
24 | }
25 |
26 | #define INT_PARAM_GET_HANDLER(FuncName, paramName) \
27 | { \
28 | std::string("/") + QUOTE(FuncName), HttpServer::Method::GET, HAN_FN { \
29 | try { \
30 | const auto param = std::stoi(req.get_param_value(paramName)); \
31 | const auto callResult = invoke(FuncName, param); \
32 | SET_CONTENT((callResult)); \
33 | } \
34 | catch (...) { \
35 | return BadRequest(res, std::string(paramName) + " is invalid"); \
36 | } \
37 | } \
38 | }
39 |
40 | #define UINT64_PARAM_GET_HANDLER(FuncName, paramName) \
41 | { \
42 | std::string("/") + QUOTE(FuncName), HttpServer::Method::GET, HAN_FN { \
43 | try { \
44 | const uint64_t param = std::stoull(req.get_param_value(paramName)); \
45 | const auto callResult = invoke(FuncName, param); \
46 | SET_CONTENT((callResult)); \
47 | } \
48 | catch (...) { \
49 | return BadRequest(res, std::string(paramName) + " is invalid"); \
50 | } \
51 | } \
52 | }
53 |
54 |
55 | inline void BadRequest(httplib::Response& res, std::string const& message) {
56 | res.status = 400;
57 | SET_CONTENT(({{"code", 400}, {"name", "Bad Request"}, {"message", message}}));
58 | }
59 |
60 | class FFIInvoke;
61 |
62 |
63 | class HttpServer {
64 | public:
65 | explicit HttpServer(FFIInvoke& ffi_invoke);
66 |
67 | // C++ enums suck.
68 | enum Method {
69 | GET,
70 | POST,
71 | PUT,
72 | PATCH,
73 | };
74 | // but im not in the mood of adding yet another dependency for just that shit here.
75 | static std::string ToString(Method m);
76 |
77 | struct Endpoint {
78 | std::string path;
79 | Method method;
80 | std::function handler;
81 | nlohmann::json response_hint = nullptr;
82 | nlohmann::json payload_hint = nullptr;
83 | };
84 |
85 | static void AddEndpoint(const Endpoint&& e);
86 | template
87 | static inline auto ParseQueryParam(const httplib::Request& req, const std::string& name, T defaultValue) -> T
88 | {
89 | T value = defaultValue;
90 | try {
91 | value = req.get_param_value(name);
92 | }
93 | catch (...) {
94 | // ignore
95 | }
96 | return value;
97 | }
98 | template <>
99 | static inline auto ParseQueryParam(
100 | const httplib::Request& req, const std::string& name, bool defaultValue) -> bool {
101 | auto value = defaultValue;
102 | try {
103 | const auto value_str = req.get_param_value(name);
104 | value = value_str == "true" || value_str == "1";
105 | }
106 | catch (...) {
107 | // ignore
108 | }
109 | return value;
110 | }
111 | template <>
112 | static inline auto ParseQueryParam(
113 | const httplib::Request& req, const std::string& name, int defaultValue) -> int {
114 | auto value = defaultValue;
115 | try {
116 | const auto value_str = req.get_param_value(name);
117 | value = std::stoi(value_str);
118 | }
119 | catch (...) {
120 | // ignore
121 | }
122 | return value;
123 | }
124 |
125 | template <>
126 | static inline auto ParseQueryParam(const httplib::Request& req, const std::string& name,
127 | unsigned long long defaultValue) -> unsigned long long {
128 | auto value = defaultValue;
129 | try {
130 | const auto value_str = req.get_param_value(name);
131 | value = std::stoll(value_str);
132 | }
133 | catch (...) {
134 | // ignore
135 | }
136 | return value;
137 | }
138 |
139 |
140 | /**
141 | * creating the endpoints and defining them with some lambdas.
142 | */
143 | void run(int port);
144 |
145 | private:
146 | httplib::Server server_;
147 | FFIInvoke& ffi_invoke_;
148 |
149 | static inline std::vector endpoints_;
150 | };
151 |
--------------------------------------------------------------------------------
/X4_Rest_Reloaded/lua_scripts/ComponentDataHelper.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 |
5 |
6 | static const std::vector valid_component_data_attribs = {
7 | // clang-format off
8 | "zoneid",
9 | "isplayerowned",
10 | "isenemy",
11 | "owner",
12 | "modulesets",
13 | "sectorid",
14 | "caninitiatecomm",
15 | "sourcesector",
16 | "revealpercent",
17 | "name",
18 | "icon",
19 | "ismissiontarget",
20 | "isonlineobject",
21 | "ishostile",
22 | "ismasstraffic",
23 | "hullpercent",
24 | "primarypurpose",
25 | "ismodule",
26 | "uirelation",
27 | "sector",
28 | "isdeployable",
29 | "isradarvisible",
30 | "ownericon",
31 | "isdocked",
32 | "assignedpilot",
33 | "assignment",
34 | "aicommandactionraw",
35 | "assignedaipilot",
36 | "iscovered",
37 | "macro",
38 | "isally",
39 | "subordinategroup",
40 | "buildingprocessor",
41 | "ismissingresources",
42 | "isfunctional",
43 | "ishacked",
44 | "issupplyship",
45 | "formation",
46 | "postname",
47 | "aicommandstack",
48 | "aicommand",
49 | "aicommandparam",
50 | "aicommandaction",
51 | "aicommandactionparam",
52 | "shiptype",
53 | "cansupplyships",
54 | "sunlight",
55 | "populationworkforcefactor",
56 | "isdatavault",
57 | "islandmark",
58 | "description",
59 | "ownername",
60 | "shiptypename",
61 | "hullmax",
62 | "hull",
63 | "shieldmax",
64 | "shield",
65 | "maxunboostedforwardspeed",
66 | "maxradarrange",
67 | "boardingstrength",
68 | "shipstoragecapacity",
69 | "numdockingbays",
70 | "size",
71 | "skills",
72 | "numtrips",
73 | "tradesubscription",
74 | "buildstorage",
75 | "money",
76 | "canequipships",
77 | "tradenpc",
78 | "isfemale",
79 | "allresources",
80 | "products",
81 | "isactive",
82 | "destination",
83 | "length",
84 | "width",
85 | "height",
86 | "wares",
87 | "shiptrader",
88 | "individualtrainee",
89 | "productionmoney",
90 | "istugweapon",
91 | "hasshipdockingbays",
92 | "missilecapacity",
93 | "countermeasurecapacity",
94 | "hasanymod",
95 | "poststring",
96 | "combinedskill",
97 | "shieldpercent",
98 | "entrygate",
99 | "cargo",
100 | "aipilot",
101 | "deployablecapacity",
102 | "blacklistgroup",
103 | "isshipyard",
104 | "iswharf",
105 | "isequipmentdock",
106 | "isnpcassignmentrestricted",
107 | "container",
108 | "iscapturable",
109 | "boardingresistance",
110 | "assigneddock",
111 | "isdock",
112 | "cluster",
113 | "clusterid",
114 | "systemid"
115 | // clang-format on
116 | };
117 |
118 | bool is_valid_component_data(const std::string& attrib) {
119 | return std::ranges::find(valid_component_data_attribs,
120 | attrib) != valid_component_data_attribs.end();
121 | }
--------------------------------------------------------------------------------
/X4_Rest_Reloaded/lua_scripts/dump_lua.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2021-2023 Peter Repukat - FlatspotSoftware
3 |
4 | Use of this source code is governed by the MIT
5 | license that can be found in the LICENSE file or at
6 | https://opensource.org/licenses/MIT.
7 | */
8 |
9 | #pragma once
10 | #include
11 |
12 | inline std::string dump_lua = R"(
13 |
14 | return json.encode(_G)
15 |
16 | )";
--------------------------------------------------------------------------------
/X4_Rest_Reloaded/lua_scripts/json.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 |
4 | inline std::string GetJsonLua(bool encode_userdata) {
5 | return R"(
6 | --
7 | -- json.lua
8 | --
9 | -- Copyright (c) 2020 rxi
10 | --
11 | -- Permission is hereby granted, free of charge, to any person obtaining a copy of
12 | -- this software and associated documentation files (the "Software"), to deal in
13 | -- the Software without restriction, including without limitation the rights to
14 | -- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
15 | -- of the Software, and to permit persons to whom the Software is furnished to do
16 | -- so, subject to the following conditions:
17 | --
18 | -- The above copyright notice and this permission notice shall be included in all
19 | -- copies or substantial portions of the Software.
20 | --
21 | -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 | -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 | -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 | -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 | -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 | -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 | -- SOFTWARE.
28 | --
29 |
30 | local json = { _version = "0.1.2" }
31 |
32 | -------------------------------------------------------------------------------
33 | -- Encode
34 | -------------------------------------------------------------------------------
35 |
36 | local encode
37 |
38 | local escape_char_map = {
39 | ["\\"] = "\\",
40 | ["\""] = "\"",
41 | ["\b"] = "b",
42 | ["\f"] = "f",
43 | ["\n"] = "n",
44 | ["\r"] = "r",
45 | ["\t"] = "t",
46 | }
47 |
48 | local escape_char_map_inv = { ["/"] = "/" }
49 | for k, v in pairs(escape_char_map) do
50 | escape_char_map_inv[v] = k
51 | end
52 |
53 |
54 | local function escape_char(c)
55 | return "\\" .. (escape_char_map[c] or string.format("u%04x", c:byte()))
56 | end
57 |
58 |
59 | local function encode_nil(val)
60 | return "null"
61 | end
62 |
63 |
64 | local function encode_table(val, stack)
65 | local res = {}
66 | stack = stack or {}
67 |
68 | -- Circular reference?
69 | if stack[val] then return '"--circular reference"' end
70 |
71 | stack[val] = true
72 |
73 | if rawget(val, 1) ~= nil or next(val) == nil then
74 | -- Treat as array -- check keys are valid and it is not sparse
75 | local n = 0
76 | for k in pairs(val) do
77 | if type(k) ~= "number" then
78 | -- error("invalid table: mixed or invalid key types")
79 | return '"invalid table: mixed or invalid key types"'
80 | end
81 | n = n + 1
82 | end
83 | if n ~= #val then
84 | -- error("invalid table: sparse array")
85 | return '"invalid table: sparse array"'
86 | end
87 | -- Encode
88 | for i, v in ipairs(val) do
89 | table.insert(res, encode(v, stack))
90 | end
91 | stack[val] = nil
92 | return "[" .. table.concat(res, ",") .. "]"
93 | else
94 | -- Treat as an object
95 | for k, v in pairs(val) do
96 | if type(k) ~= "string" then
97 | -- error("invalid table: mixed or invalid key types")
98 | goto continue
99 | end
100 | table.insert(res, encode(k, stack) .. ":" .. encode(v, stack))
101 | ::continue::
102 | end
103 | stack[val] = nil
104 | return "{" .. table.concat(res, ",") .. "}"
105 | end
106 | end
107 |
108 |
109 | local function encode_string(val)
110 | return '"' .. val:gsub('[%z\1-\31\\"]', escape_char) .. '"'
111 | end
112 |
113 |
114 | local function encode_number(val)
115 | -- Check for NaN, -inf and inf
116 | if val ~= val or val <= -math.huge or val >= math.huge then
117 | return '"' .. tostring(val) .. '"'
118 | end
119 | return string.format("%.14g", val)
120 | end
121 |
122 | local function encode_userdata(val)
123 | -- return tostring(val)
124 | return encode_number(ConvertIDTo64Bit(val))
125 | end
126 |
127 | local function encode_unsupported(val)
128 | return '"unsupported:' .. type(val) .. '"'
129 | end
130 |
131 | local type_func_map = {
132 | ["nil"] = encode_nil,
133 | ["table"] = encode_table,
134 | ["string"] = encode_string,
135 | ["number"] = encode_number,
136 | ["boolean"] = tostring,
137 | ["userdata"] = )" +
138 | (encode_userdata ? std::string{"encode_userdata"} : std::string{"encode_unsupported"}) + R"(,
139 | ["function"] = encode_unsupported
140 | }
141 |
142 |
143 | encode = function(val, stack)
144 | local t = type(val)
145 | local f = type_func_map[t]
146 | if f then
147 | return f(val, stack)
148 | end
149 | error("unexpected type '" .. t .. "'")
150 | end
151 |
152 |
153 | function json.encode(val)
154 | return (encode(val))
155 | end
156 |
157 | -------------------------------------------------------------------------------
158 | -- Decode
159 | -------------------------------------------------------------------------------
160 |
161 | local parse
162 |
163 | local function create_set(...)
164 | local res = {}
165 | for i = 1, select("#", ...) do
166 | res[select(i, ...)] = true
167 | end
168 | return res
169 | end
170 |
171 | local space_chars = create_set(" ", "\t", "\r", "\n")
172 | local delim_chars = create_set(" ", "\t", "\r", "\n", "]", "}", ",")
173 | local escape_chars = create_set("\\", "/", '"', "b", "f", "n", "r", "t", "u")
174 | local literals = create_set("true", "false", "null")
175 |
176 | local literal_map = {
177 | ["true"] = true,
178 | ["false"] = false,
179 | ["null"] = nil,
180 | }
181 |
182 |
183 | local function next_char(str, idx, set, negate)
184 | for i = idx, #str do
185 | if set[str:sub(i, i)] ~= negate then
186 | return i
187 | end
188 | end
189 | return #str + 1
190 | end
191 |
192 |
193 | local function decode_error(str, idx, msg)
194 | local line_count = 1
195 | local col_count = 1
196 | for i = 1, idx - 1 do
197 | col_count = col_count + 1
198 | if str:sub(i, i) == "\n" then
199 | line_count = line_count + 1
200 | col_count = 1
201 | end
202 | end
203 | error(string.format("%s at line %d col %d", msg, line_count, col_count))
204 | end
205 |
206 |
207 | local function codepoint_to_utf8(n)
208 | -- http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=iws-appendixa
209 | local f = math.floor
210 | if n <= 0x7f then
211 | return string.char(n)
212 | elseif n <= 0x7ff then
213 | return string.char(f(n / 64) + 192, n % 64 + 128)
214 | elseif n <= 0xffff then
215 | return string.char(f(n / 4096) + 224, f(n % 4096 / 64) + 128, n % 64 + 128)
216 | elseif n <= 0x10ffff then
217 | return string.char(f(n / 262144) + 240, f(n % 262144 / 4096) + 128,
218 | f(n % 4096 / 64) + 128, n % 64 + 128)
219 | end
220 | error(string.format("invalid unicode codepoint '%x'", n))
221 | end
222 |
223 |
224 | local function parse_unicode_escape(s)
225 | local n1 = tonumber(s:sub(1, 4), 16)
226 | local n2 = tonumber(s:sub(7, 10), 16)
227 | -- Surrogate pair?
228 | if n2 then
229 | return codepoint_to_utf8((n1 - 0xd800) * 0x400 + (n2 - 0xdc00) + 0x10000)
230 | else
231 | return codepoint_to_utf8(n1)
232 | end
233 | end
234 |
235 |
236 | local function parse_string(str, i)
237 | local res = ""
238 | local j = i + 1
239 | local k = j
240 |
241 | while j <= #str do
242 | local x = str:byte(j)
243 |
244 | if x < 32 then
245 | decode_error(str, j, "control character in string")
246 | elseif x == 92 then -- `\`: Escape
247 | res = res .. str:sub(k, j - 1)
248 | j = j + 1
249 | local c = str:sub(j, j)
250 | if c == "u" then
251 | local hex = str:match("^[dD][89aAbB]%x%x\\u%x%x%x%x", j + 1)
252 | or str:match("^%x%x%x%x", j + 1)
253 | or decode_error(str, j - 1, "invalid unicode escape in string")
254 | res = res .. parse_unicode_escape(hex)
255 | j = j + #hex
256 | else
257 | if not escape_chars[c] then
258 | decode_error(str, j - 1, "invalid escape char '" .. c .. "' in string")
259 | end
260 | res = res .. escape_char_map_inv[c]
261 | end
262 | k = j + 1
263 | elseif x == 34 then -- `"`: End of string
264 | res = res .. str:sub(k, j - 1)
265 | return res, j + 1
266 | end
267 |
268 | j = j + 1
269 | end
270 |
271 | decode_error(str, i, "expected closing quote for string")
272 | end
273 |
274 |
275 | local function parse_number(str, i)
276 | local x = next_char(str, i, delim_chars)
277 | local s = str:sub(i, x - 1)
278 | local n = tonumber(s)
279 | if not n then
280 | decode_error(str, i, "invalid number '" .. s .. "'")
281 | end
282 | return n, x
283 | end
284 |
285 |
286 | local function parse_literal(str, i)
287 | local x = next_char(str, i, delim_chars)
288 | local word = str:sub(i, x - 1)
289 | if not literals[word] then
290 | decode_error(str, i, "invalid literal '" .. word .. "'")
291 | end
292 | return literal_map[word], x
293 | end
294 |
295 |
296 | local function parse_array(str, i)
297 | local res = {}
298 | local n = 1
299 | i = i + 1
300 | while 1 do
301 | local x
302 | i = next_char(str, i, space_chars, true)
303 | -- Empty / end of array?
304 | if str:sub(i, i) == "]" then
305 | i = i + 1
306 | break
307 | end
308 | -- Read token
309 | x, i = parse(str, i)
310 | res[n] = x
311 | n = n + 1
312 | -- Next token
313 | i = next_char(str, i, space_chars, true)
314 | local chr = str:sub(i, i)
315 | i = i + 1
316 | if chr == "]" then break end
317 | if chr ~= "," then decode_error(str, i, "expected ']' or ','") end
318 | end
319 | return res, i
320 | end
321 |
322 |
323 | local function parse_object(str, i)
324 | local res = {}
325 | i = i + 1
326 | while 1 do
327 | local key, val
328 | i = next_char(str, i, space_chars, true)
329 | -- Empty / end of object?
330 | if str:sub(i, i) == "}" then
331 | i = i + 1
332 | break
333 | end
334 | -- Read key
335 | if str:sub(i, i) ~= '"' then
336 | decode_error(str, i, "expected string for key")
337 | end
338 | key, i = parse(str, i)
339 | -- Read ':' delimiter
340 | i = next_char(str, i, space_chars, true)
341 | if str:sub(i, i) ~= ":" then
342 | decode_error(str, i, "expected ':' after key")
343 | end
344 | i = next_char(str, i + 1, space_chars, true)
345 | -- Read value
346 | val, i = parse(str, i)
347 | -- Set
348 | res[key] = val
349 | -- Next token
350 | i = next_char(str, i, space_chars, true)
351 | local chr = str:sub(i, i)
352 | i = i + 1
353 | if chr == "}" then break end
354 | if chr ~= "," then decode_error(str, i, "expected '}' or ','") end
355 | end
356 | return res, i
357 | end
358 |
359 |
360 | local char_func_map = {
361 | ['"'] = parse_string,
362 | ["0"] = parse_number,
363 | ["1"] = parse_number,
364 | ["2"] = parse_number,
365 | ["3"] = parse_number,
366 | ["4"] = parse_number,
367 | ["5"] = parse_number,
368 | ["6"] = parse_number,
369 | ["7"] = parse_number,
370 | ["8"] = parse_number,
371 | ["9"] = parse_number,
372 | ["-"] = parse_number,
373 | ["t"] = parse_literal,
374 | ["f"] = parse_literal,
375 | ["n"] = parse_literal,
376 | ["["] = parse_array,
377 | ["{"] = parse_object,
378 | }
379 |
380 |
381 | parse = function(str, idx)
382 | local chr = str:sub(idx, idx)
383 | local f = char_func_map[chr]
384 | if f then
385 | return f(str, idx)
386 | end
387 | decode_error(str, idx, "unexpected character '" .. chr .. "'")
388 | end
389 |
390 |
391 | function json.decode(str)
392 | if type(str) ~= "string" then
393 | error("expected argument of type string, got " .. type(str))
394 | end
395 | local res, idx = parse(str, next_char(str, 1, space_chars, true))
396 | idx = next_char(str, idx, space_chars, true)
397 | if idx <= #str then
398 | decode_error(str, idx, "trailing garbage")
399 | end
400 | return res
401 | end
402 | )";
403 | }
--------------------------------------------------------------------------------