home.social

#starcitizen — Public Fediverse posts

Live and recent posts from across the Fediverse tagged #starcitizen, aggregated by home.social.

  1. Making use of StarCitizen ship telemetry API

    Alright time for a quick write-up before I forget all of this again. So @[email protected] posted that Star Citizen is about to get an API for ship telemetry. Some of us have been waiting for this for years. This is basically what allows avid home cockpit or button box makers like myself to sync the state of the game with our blinken lights.

    Getting this data in a somewhat realtime-ish matter is also important for people that use motion rigs at home. And it is not often that we get such data in space pew pew related games, since this is usually something only done by “real” flight sims or racing sims.

    With this out of the way down to the meat. Keep in mind that this is in it’s early days and subject to change. So according to https://gameglass.gg/games/star-citizen/data we even get some data on LIVE already, while PTU has in theory more but had this feature disabled again. @[email protected] suggested that this might have been done by accident and that apparently more feature are about to come soon™.

    The API itself has to be enabled first, which is different between LIVE and PTU. The API becomes available on local port 2942 (I see what you did there, CIG), as gRPC interface, which is short for Remote Procedure Call (yeah and the g… well Google apparently shipped this out) framework, a HTTP/2 protobuf protocol.

    That’s right, anything can connect to this port on localhost and start using the firehose style data once enabled. There is even an option to write back data/commands.

    To do so one needs a “.proto” file. This is a plain text human readable service and message definition file. It can be used to generate code to interface with this for various languages, like Python or TypeScript. Such a “.proto” file is usually provided by whoever implements this but since this is rather early we simply don’t get one shipped. And I can kinda understand this. Things are still in motion and I expect this to change again and again.

    We’re in luck though, since such a “.proto” file can be generated straight from the StarCitizen EXE. The user Purzifal provided a nice example of this at https://github.com/Purzifal/sc_make_proto using Python 3. Alas this is watching for a running Star Citizen process to always generate the best “.proto” file no matter if playing on LIVE or PTU. Naturally as a Linux PC gamer I had to kick out the Windows-only parts to make this work:

    diff --git make_proto.py make_proto.py
    old mode 100644
    new mode 100755
    index 381b330..aa33bcd
    --- make_proto.py
    +++ make_proto.py
    @@ -55,6 +55,7 @@ class _ProcessEntry(ctypes.Structure):
     
     
     # Exact signatures so 64-bit handles are passed correctly.
    +"""
     _k32 = ctypes.WinDLL("kernel32")
     _k32.CreateToolhelp32Snapshot.restype = wintypes.HANDLE
     _k32.OpenProcess.restype = wintypes.HANDLE
    @@ -67,9 +68,8 @@ _k32.QueryFullProcessImageNameW.argtypes = (
     )
     _k32.CloseHandle.argtypes = (wintypes.HANDLE,)
     
    -
     def find_exe_path() -> str | None:
    -    """Return the full path of the running StarCitizen.exe, or None."""
    +    # Return the full path of the running StarCitizen.exe, or None.
         # Snapshot all processes (0x2 = TH32CS_SNAPPROCESS) and find the game.
         snapshot = _k32.CreateToolhelp32Snapshot(0x2, 0)
         entry = _ProcessEntry(dwSize=ctypes.sizeof(_ProcessEntry))
    @@ -98,6 +98,7 @@ def find_exe_path() -> str | None:
             return buffer.value if ok else None
         finally:
             _k32.CloseHandle(handle)
    +"""
     
     
     def _file_version(data: mmap.mmap) -> str | None:
    @@ -360,8 +361,9 @@ def build(exe_path: str) -> tuple[str | None, str | None]:
     
     if __name__ == "__main__":
         print(f"Waiting for {EXE_NAME} to start...")
    -    while (exe := find_exe_path()) is None:
    -        time.sleep(CHECK_INTERVAL)
    +    # while (exe := find_exe_path()) is None:
    +    #    time.sleep(CHECK_INTERVAL)
    +    exe = f"/games/star-citizen/drive_c/Program Files/Roberts Space Industries/StarCitizen/LIVE/Bin64/{EXE_NAME}"
         file_version, proto_text = build(exe)
         if proto_text is None:
             print("No telemetry proto found")
    

    Looks like much but really isn’t. I simply uncommented all of the _k32 variables, the find_exec_path function and hard coded the path to the location of my StarCitizen EXE.

    Running this Python script now creates the needed “.proto” files just fine. I threw the result on Pastebin at https://pastebin.com/HBkReUER (4.10.201.48085) and https://pastebin.com/rEFrZVgx (5.0.202.46035) if you’re interested. Keep in mind that this may be obsolete tomorrow already.

    From here I edited my USER.cfg and added the following lines for v5:

    server.game.telemetry.enabled = 1
    server.game.telemetry.debug.displayinfo = 1
    grpc.client.server.enabled = 1
    grpc.client.server.port = 2942

    The environment variable for v4 goes straight into sc-launch.sh, that’s the launch script from the SC LUG-Helper, that all Linux players running Star Citizen will know about:

    export GRPC_CLIENT_SERVER_ENABLED="true"

    With this I’m all set for LIVE or PTU (well, once this is enabled on PTU again).

    Next I jumped into the Arena Commander and started a Free Flight map and watched the port 2942 to come up with the usual ss -tulpen command.

    Time to consume this! How you do this is really up to you. I use node-red for this, since this is where my plumbing pipeline *for several* games is done with. Connects to almost anything and I can change it quickly when new patches drop. There are several packages that will work here but I just added a function node and copied the following two modules to the Setup tab: @grpc/grpc-js imported as “grpc” and @grpc/proto-loader imported as protoLoader. This fetches the node libs for both on start so you may want to read up on the packages on GitHub first.

    Here is some code for the Start tab to read the generated proto file and connect to the game:

    const PROTO_PATH = '/games/star-citizen/sc_telemetry.proto';
    
    const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
        keepCase: true,
        longs: String,
        enums: String,
        defaults: false,
        oneofs: true
    });
    
    const protoDescriptor = grpc.loadPackageDefinition(packageDefinition);
    const TelemetryService = protoDescriptor.sc.game.telemetry.v1.GameTelemetryService;
    
    const client = new TelemetryService(
        '127.0.0.1:2942',
        grpc.credentials.createInsecure()
    );
    
    const call = client.TelemetryStream({});
    
    call.on('data', (telemetryData) => {
        node.send({ payload: telemetryData });
    });
    
    call.on('error', (err) => {
        node.warn(`gRPC stream error: ${err.message}`);
    });
    
    call.on('end', () => {
        node.status({ fill: 'yellow', shape: 'ring', text: 'stream ended' });
    });
    
    context.set('grpcCall', call);

    Function is left with the default return msg;

    And the Stop tab gets this for clean termination on end:

    const call = context.get('grpcCall');
    if (call) call.cancel();

    And that’s it. Plug that into a debug node or another function node and start using the data 🤓 You may need a rate limiter. Important: This does not re-connect automatically and is just a proof of concept. Just restart node-red or adjust to your needs.

    Finally we can drive that blinken lights in our home cockpits (a Macross inspired VF-1 panel in my case).

    Watch a very brief demo snippet what can be done with this: https://www.youtube.com/watch?v=BahRajA09IY [unlisted] / https://loops.video/v/jFf3u4VG_4

    Now go, start making cool things with this 🤓

    #flightsim #gRPC #homeCockpit #macross #NodeRed #simpit #Space #SpacePewPew #StarCitizen #VF1 #VF1
  2. ngl, never thought I'd see the day that #StarCitizen makes good on their promise to provide an API for ship telemetry but here we are at the end of 2026 and this thing starts blabbing ship status data on the wire.

    #HomeCockpit #FlightSim #SpacePewPew #Space #SimPit

Share on Mastodon

Enter the server where you have an account.