Skip to content

A C++ wrapper for .NET NativeAOT runtime internals

Notifications You must be signed in to change notification settings

KillStr3aK/nativeaot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

NativeAOT C++ Wrapper Library

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.

What This Is

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.

Important

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)

Requirements

  • C++
    • 17 (minimum)
    • 20+ (recommended, I use 23 preview)
  • .NET NativeAOT runtime (tested with .NET 10)

Setup

You need to add the include and impl folders to the project AdditionalIncludeDirectories and the NativeAOT.cpp to the compilation units

Visual Studio

<AdditionalIncludeDirectories>
  $(ProjectDir)vendor\nativeaot\include;
  $(ProjectDir)vendor\nativeaot\impl;
</AdditionalIncludeDirectories>

<ClCompile Include="vendor\nativeaot\src\NativeAOT.cpp" />

CMake

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)

Layout

nativeaot/
├── include/
│   ├── NativeAOT.h      # Main include
│   ├── ...
│   └── Types/           # Managed type wrappers
├── impl/                # Implementations
└── src/
    └── NativeAOT.cpp    # Main compile unit

Example

https://github.com/KillStr3aK/NativeAOTRuntimeDumper

About

A C++ wrapper for .NET NativeAOT runtime internals

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published