[MOD/API] X4RestServer - External http API

The place to discuss scripting and game modifications for X4: Foundations.

Moderators: Moderators for English X Forum, Scripting / Modding Moderators

Rezoken
Posts: 13
Joined: Sat, 6. Feb 16, 08:54
x4

Re: [MOD/API] X4RestServer - External http API

Post by Rezoken » Tue, 12. May 20, 17:34

Do we have any indication from the X4 Devs that the DLL injection is not going to possibly be flagged through Steam or anything like that?

ShoC
Posts: 693
Joined: Sun, 8. Feb 04, 15:06
x4

Re: [MOD/API] X4RestServer - External http API

Post by ShoC » Wed, 13. May 20, 09:58

Wow this is exciting !!

You have given me a project. (If I get a chance)

Make a website for displaying all the data, I'd look at logging account finance and storing that to an SQL lite data-base and use Google API to make charts showing asset changes over time periods chosen.

What would be interesting is getting global averages for all product prices and seeing how they change over time.

Man this is awesome!
they have had almost 1000 years to terraform Aldrin, why are they all still sitting around a giant rock?

Catra wrote:
because you cant terraform a rock.

Exi
Posts: 24
Joined: Tue, 2. Dec 03, 22:20
x3tc

Re: [MOD/API] X4RestServer - External http API

Post by Exi » Wed, 21. Oct 20, 20:17

Reading this literally made me jump back into the X universe, after a very long break. Years ago I've made a mod for X3 TC/AP which displayed ingame information on the Saitek X52 Pro's display, and also used the LEDs on the controller for various feedback. Your work could make it possible to port this to X4 now, and it could be even better than the original due to the possibilities in this API. I've waited out with X4 for quite long, but this was a trigger.
So I'm looking forward to see more of your work, and a big thank your for all the time invested in this.

kuertee
EGOSOFT
EGOSOFT
Posts: 789
Joined: Sun, 14. Dec 03, 13:05
x4

Re: [MOD/API] X4RestServer - External http API

Post by kuertee » Thu, 22. Oct 20, 13:55

bookmarked :)
Mods: RPG: Reputations and Professions, Social Standings and Citizenships, Crime has Consequences, Alternatives to Death. Missions/NPCs: Emergent Missions, NPC Reactions, Mod Parts Trader, High-sec Rooms are Locked, Hacking Outcomes, More Generic Missions, Waypoint Fields for Deployment. Others: Auto-cam, Friendly Fire Tweaks, Teleport From Transporter Room, Wear and Tear. QoL: Trade Analytics, Loot Mining, Ship Scanner, Signal Leak Hunter, Station Scanner, Surface Element Targeting, etc.

User avatar
beko
Posts: 53
Joined: Thu, 11. Jun 20, 21:14
x4

Re: [MOD/API] X4RestServer - External http API

Post by beko » Sat, 1. May 21, 21:29

I want to report a bug: This project is way to exciting!

I got it running on Linux
Spoiler
Show
and may be aroused :o

Cadbury
Posts: 7
Joined: Sun, 17. Nov 19, 21:57
x4

Re: [MOD/API] X4RestServer - External http API

Post by Cadbury » Sat, 1. May 21, 23:43

How did you get it running on Linux? I'm using the steam version and have followed the instructions but the game never starts. I can see the process running but it's not doing anything and no window appears :(

If I run the exe without the LD_PRELOAD, it still doesn't start which makes me think it's something about the steam exe that's causing issues (when steam isn't running).

User avatar
beko
Posts: 53
Joined: Thu, 11. Jun 20, 21:14
x4

Re: [MOD/API] X4RestServer - External http API

Post by beko » Sun, 2. May 21, 00:00

Cadbury wrote:
Sat, 1. May 21, 23:43
How did you get it running on Linux? I'm using the steam version and have followed the instructions but the game never starts. I can see the process running but it's not doing anything and no window appears :(
Not so easy with Steam. I'm running the GOG version and I'm starting it just like that after the lib was compiled:

Code: Select all

LD_PRELOAD="${LD_PRELOAD}:/games/linux/X4_Foundations/game/lib/X4RestServer.so" ./X4 -skipintro
I did move the lib into the game lib folder though. Game starts fine and the server is raised on port 3000 (hint: 0.0.0.0 is free for all, anyone on the net/wlan can talk to this now and break your game)

Code: Select all

beko  ~  lsof -i tcp:3000
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
Main()  73073 beko    5u  IPv4 517725      0t0  TCP *:hbci (LISTEN)
YOU will probably have to set the Steam start options so something like this (don't hold me to that - not so firm with Steam)

Code: Select all

LD_PRELOAD="/path/to/X4RestServer.so" %command% -skipintro 
The FFIRipper is giving me some trouble but that's not required to talk to the server from my understanding. It just builds the references for available FFI stuff. Postponed - playing with the server is way more fun right now :D

User avatar
beko
Posts: 53
Joined: Thu, 11. Jun 20, 21:14
x4

Re: [MOD/API] X4RestServer - External http API

Post by beko » Sun, 2. May 21, 18:37

I'm having way too much fun with this. Did some plumbing today and this is the result :D

Image
Short screen recording: https://beko.famkos.net/2021/05/02/auto-draft/
The flight instruments are from https://github.com/uw-ray/Skyhawk-Flight-Instruments and are not for a spaceship - obviously

I patched the http server to send Access-Control-Allow-Origin so the browser wouldn't refuse to load. Could set up a proxy but I wanted results fast :roll:

* Speed is also mapped to ALT as Fast Travel speed
* It reads just the camera position and not really the ship position (and since there is no up and down in space it settles fast on the new artificial horizon - may need some more tuning)
* Plumbed the speed to the pressure so it starts creeping up from 27.1 inHg to 33 inHg (max on the instrument) when speed goes over 200. Just for fun.
* Turn Coordinator is just Camera yaw + left or right based on mouse/pointer X.
* Some target data as proof of concept

This worked out better than expected and the best thing is: Doesn't need to run on the same computer - it just has to be on the net so a tiny Raspberry and some external display would be enough for some fun cockpit building 8)

kuertee
EGOSOFT
EGOSOFT
Posts: 789
Joined: Sun, 14. Dec 03, 13:05
x4

Re: [MOD/API] X4RestServer - External http API

Post by kuertee » Sun, 2. May 21, 19:13

nice!
Mods: RPG: Reputations and Professions, Social Standings and Citizenships, Crime has Consequences, Alternatives to Death. Missions/NPCs: Emergent Missions, NPC Reactions, Mod Parts Trader, High-sec Rooms are Locked, Hacking Outcomes, More Generic Missions, Waypoint Fields for Deployment. Others: Auto-cam, Friendly Fire Tweaks, Teleport From Transporter Room, Wear and Tear. QoL: Trade Analytics, Loot Mining, Ship Scanner, Signal Leak Hunter, Station Scanner, Surface Element Targeting, etc.

Mycu
Posts: 408
Joined: Fri, 28. Sep 12, 08:30
x4

Re: [MOD/API] X4RestServer - External http API

Post by Mycu » Sun, 2. May 21, 20:30

beko wrote:
Sun, 2. May 21, 18:37
I'm having way too much fun with this. Did some plumbing today and this is the result :D
Great that you found this project and nice results so far.
I can't wait to see where this gets to. So many possibilities.
X3 AP 3.1 + XRM
X3 AP 3.1 + LU

Mamy la Puce
Posts: 528
Joined: Sun, 1. Apr 07, 16:18
x4

Re: [MOD/API] X4RestServer - External http API

Post by Mamy la Puce » Mon, 14. Jun 21, 17:26

How could I use this mod to know some data like for example if the player is on foot or at the controls of a ship, if he take off from the station (or ship docking deck) or is he still docked ? My goal is to be able to use this "feedback" to set up my VoiceAttack profile and that’s typically what I’m looking for !! Does your mod inform about this kind of thing in a text (.json) file ? If so, where can I find this file ?

Here is my Request on the forum : viewtopic.php?f=146&t=439757

User avatar
beko
Posts: 53
Joined: Thu, 11. Jun 20, 21:14
x4

Re: [MOD/API] X4RestServer - External http API

Post by beko » Mon, 14. Jun 21, 20:02

Mamy la Puce wrote:
Mon, 14. Jun 21, 17:26
How could I use this mod to know some data like for example if the player is on foot or at the controls of a ship, if he take off from the station (or ship docking deck) or is he still docked ? My goal is to be able to use this "feedback" to set up my VoiceAttack profile and that’s typically what I’m looking for !! Does your mod inform about this kind of thing in a text (.json) file ? If so, where can I find this file ?
It's providing various documented functions via a REST route returning data as json. This means once running you have to request the data you need via http from the server probably running on localhost. This is described on the project page. You basically have to query the information of interest and poll that information in a loop.

Here is an example to poll for the PlayerShipID in JS:

Code: Select all

        var server =  'http://localhost:3000/';
        var shipID = 0;
        setInterval(function() {
            fetch(`${server}GetPlayerShipID`).then((r) => r.json())
            .then((data) => {
                if(data.func_res !== shipID){
                    console.log('ShipID changed', data.func_res);
                    shipID = data.func_res;
                }
            })
            .catch((e) => null)
        }, 2000);
(It's also an alpha version and a proof of concept - get's real crash happy for me after some time)

Mamy la Puce
Posts: 528
Joined: Sun, 1. Apr 07, 16:18
x4

Re: [MOD/API] X4RestServer - External http API

Post by Mamy la Puce » Mon, 14. Jun 21, 22:26

As you can see, i know nothing about coding, but i understand what it is for and yeah, it is what i was searching for ^^ Now i need to know, to learn how i can use it or find someone who could help me for that. It's a very good start to begin something around it in order to build VoiceAttack profiles like those from HCS Voices, having a "game feedback" is exactly what X4 needed for VA to do the same thing as for Elite Dangerous : build profiles around "Real Time Game Data Variables" !!

(sorry if my english is bad, not my first language)

Post Reply

Return to “X4: Foundations - Scripts and Modding”