hao-il2cpp
Read Unity Il2Cpp games and regenerate their .NET assemblies with hao: typed
declaration ("dummy") DLLs to browse in ILSpy and compile against. Calling the game at runtime is
done from Rust with hao-il2cpp-runtime, not a managed C# host — so
these assemblies are reference artifacts, and the execution path is Rust rather than
Il2CppInterop-style managed proxies.
Work in progress. What's here so far:
-
global-metadata.datreader for metadata v29 (Unity 2021.2 – 2023.x) and v39 (Unity 6): images, assemblies, types, methods, fields, parameters, properties, events and generic parameters, with names -
GameAssemblybinary, ELF (.so) and PE (.dll): findsMetadataRegistrationand decodes theIl2CppTypetable, giving the types of fields, parameters and return values. Validated end-to-end on a native Linux game (v29) and a Windows / Unity 6 game (v39). - declaration assemblies ("dummy DLLs"): one assembly per image with every type, field, constant, method signature, property, event, generic parameter and interface, with stub bodies. Other code compiles against them.
-
CodeRegistration: resolves each method's native code address inGameAssembly(MethodView::code_address,Game::method_pointer) - custom attributes: recovers each member's attributes and their fixed/named argument
values from v29+ metadata (primitives, strings, enums, simple
System.Type, arrays); attributes whose blob can't be re-encoded exactly (objectparams, generic/arrayType) are dropped, never guessed - metadata v31 (later Unity 2022.3 LTS / 2023.x): implemented from the Il2CppDumper/Il2CppInspector reference layout — unverified against a real v31 game
- call the game's methods at runtime — done from Rust, not a managed C# host. The
generated assemblies are reference artifacts (browse in ILSpy, compile against); live calls
and hooks run through
hao-il2cpp-runtime's typedcall/hook, and the(image, token)identity each method carries resolves to a liveMethodInfowithIl2Cpp::method(image, token)— the online mirror ofBinary::method_pointer. A managed C#-consumer stack à la Il2CppInterop is intentionally out of scope.
use Game;
let game = open?; // the folder with GameAssembly.so and <Game>_Data
let health = game.find_type.unwrap;
println!;
for field in health.fields
for method in health.methods
// One declaration assembly per image, for ILSpy or to compile against.
game.write_assemblies?;
Declaration assemblies
An Il2Cpp game ships no .NET assemblies: its C# was compiled to C++ and then to native code in
GameAssembly. What's left of the original assemblies is global-metadata.dat, which has every
type, method and field name but no code. write_assemblies (and the generate_dlls example)
rebuild one ordinary .NET assembly per original assembly from it: every type, field, constant,
property, event and method signature, with method bodies that just throw. They're useful for:
- browsing the game in ILSpy, dnSpy or Rider to find what a mod should hook or read
(for
hao-il2cpp-runtime), with exact names and signatures - compiling C# against the game's API, since the declarations match the real types
- comparing game versions to see what an update changed
They contain no game logic: for that you'd disassemble GameAssembly.
Game is built on the lower level Metadata (global-metadata.dat) and Binary (the
Il2CppType table from GameAssembly), which are public for anything the views don't cover.
Tests
The tests need a real game, which you point them at:
HAO_IL2CPP_GAME=/path/to/game
HAO_IL2CPP_GAME is a game folder with a v29 GameAssembly.so and *_Data/il2cpp_data.
HAO_IL2CPP_METADATA can point the metadata tests at a global-metadata.dat directly. Without
either the tests skip themselves. Game files are never committed.