A C++ wrapper for .NET NativeAOT runtime internals, reverse-engineered from the Hytale game client, some code taken from the dotnet runtime repository. Provides direct access to managed types and methods from native code.
This library exposes .NET NativeAOT's internal type system to C++, allowing you to:
- Access managed objects from native code
- Call virtual methods on any .NET object
- Perform runtime type inspection
- Originally created for modding the Hytale game client, but might be useful for any NativeAOT application.
This library does nothing by itself! It's just a set of type definitions and wrapper classes. You have to initialize the API functions that you intend to use (see example below)
- C++
- 17 (minimum)
- 20+ (recommended, I use 23 preview)
- .NET NativeAOT runtime (tested with .NET 10)
You need to add the include and impl folders to the project AdditionalIncludeDirectories and the NativeAOT.cpp to the compilation units
<AdditionalIncludeDirectories>
$(ProjectDir)vendor\nativeaot\include;
$(ProjectDir)vendor\nativeaot\impl;
</AdditionalIncludeDirectories>
<ClCompile Include="vendor\nativeaot\src\NativeAOT.cpp" />
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/vendor/nativeaot/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/vendor/nativeaot/impl)
add_library(nativeaot STATIC vendor/nativeaot/src/NativeAOT.cpp)
nativeaot/
├── include/
│ ├── NativeAOT.h # Main include
│ ├── ...
│ └── Types/ # Managed type wrappers
├── impl/ # Implementations
└── src/
└── NativeAOT.cpp # Main compile unit