X4Native — Native C++ Extension Framework for X4: Foundations [Beta]

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

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

eg3r
Posts: 11
Joined: Mon, 16. Mar 26, 12:45

X4Native — Native C++ Extension Framework for X4: Foundations [Beta]

Post by eg3r »

X4Native — Native C++ Extension Framework for X4: Foundations [Beta]

Hey everyone,

I've been working on something for X4 modders who've hit the limits of what Lua and MD XML can do on their own: X4Native — an open-source framework that lets you write X4 mods in C++, with direct access to the game's internals.

Lua is great for UI and glue code, and Mission Director handles game logic well — but some things just aren't possible (or practical) without native code. Think: intercepting game function calls, accessing the full range of 2,000+ exported game functions with proper typing, building performance-critical logic, or bridging game systems in ways Lua alone can't reach. X4Native fills that gap.

This is a first public release. The core framework is functional and tested, but the API may still evolve. Feedback and bug reports are very welcome.

Features
  • Full access to X4's exported API (GetPlayerID, GetComponentName, IsPlayerValid, etc.)
  • Function hooking — before/after hooks on any game function (inspect args, modify behavior, skip calls)
  • Event system — lifecycle events, custom C++ events, and Lua-to-C++ bridges without writing any Lua
  • Hot-reloadable core — /reloadui picks up new DLL builds without restarting the game
  • Clean C++ SDK — modern C++23, single #include <x4native.h>, everything in the x4n:: namespace
  • Auto-discovery — drop extension folders into extensions/, the framework finds and loads them
Quick Example

Code: Select all

#include <x4native.h>

X4N_EXTENSION {
    x4n::log::info("Hello X4!");

    x4n::on("on_game_loaded", [] {
        auto* game = x4n::game();
        UniverseID player = game->GetPlayerID();
        x4n::log::info("Player ID: {}", player);
    });
}
Installation (Players - Currently no value, unless extensions exist)
  1. Download x4native-vXXX.zip from the Releases page
  2. Extract into your X4 extensions/ folder so you have extensions/x4native/
  3. Disable Protected UI mode in game settings (Settings → Extensions → uncheck Protected Mode)
  4. Launch the game — check extensions/x4native/x4native.log to verify it loaded
Building Extensions (Developers)
  1. Grab the SDK zip from the same Releases page
  2. Point your CMake project at the sdk/ headers
  3. Build a DLL, drop it in an extension folder with a content.xml and x4native.json, done
Full developer guide with API docs, hook examples, Lua bridging, and MD event forwarding:
Extension Developer Guide

Links
Requirements: X4: Foundations v9+ (current beta), Windows x64, Protected UI mode OFF.

This is a beta — if you run into issues or have suggestions, open an issue on GitHub or reply here. I'm looking forward to your input.

Happy modding!
Last edited by eg3r on Tue, 21. Apr 26, 20:39, edited 1 time in total.
User avatar
ChemODun
Posts: 598
Joined: Mon, 12. Feb 07, 21:58
x4

Re: X4Native — Native C++ Extension Framework for X4: Foundations [Beta]

Post by ChemODun »

Sounds interesting, but your LLM not fully understand a content.xml structure… ;-)
Multiply entropy by absolute zero

Freedom in space
eg3r
Posts: 11
Joined: Mon, 16. Mar 26, 12:45

Re: X4Native — Native C++ Extension Framework for X4: Foundations [Beta]

Post by eg3r »

Thank you for your feedback! It will get its tokens reduced for a week as punishment for the oversight. 8)
User avatar
beko
Posts: 91
Joined: Thu, 11. Jun 20, 21:14
x4

Re: X4Native — Native C++ Extension Framework for X4: Foundations [Beta]

Post by beko »

> Windows x64

:| was interested until that. None around, can't test, don't see why this is a requirement :sceptic:
IlikeThisgame
Posts: 41
Joined: Fri, 18. Apr 25, 19:32

Re: X4Native — Native C++ Extension Framework for X4: Foundations [Beta]

Post by IlikeThisgame »

sad that this has to come 8 years after release from a user, but ill sure test it, when i have time, i think about writing x4 mods now for a long time.
eg3r
Posts: 11
Joined: Mon, 16. Mar 26, 12:45

Re: X4Native — Native C++ Extension Framework for X4: Foundations [Beta]

Post by eg3r »

beko wrote: Tue, 24. Mar 26, 11:40 > Windows x64

:| was interested until that. None around, can't test, don't see why this is a requirement :sceptic:
Hi there! I knew this question would come sooner or later 8)

Let me first say it was a deliberate decision for the beta (and probably fervor once you understood the underlying problems).

This is a hooking library to give extension developers benefits compared to the current extension system of X4:
  • Access functionality that is not exposed or too internalized to be exposed to current extensions
  • Give a possibility to continue writing in their favorite language (which is obviously C++) and not dive into lua or md (too deep)
  • Circumvent the performance overhead of lua or md
With that a certain need arises that is a very "special" field in computer science: Reverse Engineering
And so comes the question of builds into the spotlight: Address-Spaces
Which are very different for a windows and for example a linux build binary.

Lets assume Egosoft releases per year 2 major versions and per each about 4 hotfix versions, that means whoever reverse engineers certain "custom" things in this project would need to do it for all of the supported operating systems (would be 2x lin/win). This is a hobby project and the time needed even when using latest tech (like LLMs) is still not zero. Beside I would need to run the game and the whole testing/dev/re setup on my linux machine too, the effort is huge.

The good news are
:
  • Current X4Native architecture would pretty much support 2 OS builds (just need to replace minhook with something like funchook)
  • It is completely open source and under the MIT license, everybody is welcome to contribute
  • easy build system adjustments

So whoever wants to support a native linux build, get in touch!


With that said, I will of course keep the ~4 native linux extension devs out there in mind with feature releases.

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

Re: X4Native — Native C++ Extension Framework for X4: Foundations [Beta]

Post by beko »

Nope, don't see it but hey it's your party 🤷

The X4RestServer did pull it off before too but that went nowhere for years.

Guess I'll stick with my socket approach.
eg3r
Posts: 11
Joined: Mon, 16. Mar 26, 12:45

Re: X4Native — Native C++ Extension Framework for X4: Foundations [Beta]

Post by eg3r »

beko wrote: Wed, 25. Mar 26, 10:35 Nope, don't see it but hey it's your party 🤷

The X4RestServer did pull it off before too but that went nowhere for years.

Guess I'll stick with my socket approach.
Hi, I see.

My point is, you certainly can "pull it off". But there are time and resource constrains on me to do so.

Thank you for the discussion.

:x4:

Return to “X4: Foundations - Scripts and Modding”