hao-il2cpp
Read Unity Il2Cpp games, with the goal of generating .NET proxy assemblies for them with
hao, the way Il2CppInterop does for MelonLoader.
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.
- custom attributes (only
[DefaultMember]for indexers is generated so far) - more metadata versions (v31)
-
CodeRegistrationand method addresses - runtime proxy assemblies that call into the game, like Il2CppInterop
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.