Modify engine assemblies table deserialized from ScriptingAssemblies.json
by replacing dummy assembly name, so you can load other assembly dynamically without need to add them in json before build.
This repo is target to game programmer who want to use IL2CPP while supporting mod.
HybridCLR
Since support C# modding for IL2CPP is not HybridCLR designed for, you should do some work to make it come true:
- Replace
Editor\BuildProcessors\PatchScriptingAssemblyList.cs
of HybridCLR unity package to pre-add mod assembly place holders - Hardcode external assemblies info path in
il2cpp-api.cpp
(eg.{PersistentDataPath}/external.txt
) - Write your mod assemblies name to info file (eg.
Kurisu.Mod.Test
, do not add suffix which should be.dll.bytes
)
Currently it can support modding for Windows and Android.
- Do aot pre-process in your game source code for preventing generic stripping problem in mod assemblies (also providing mod interface access to game api is better than let modder use reflection since it may cause problem above)
- Mod assembly's name should smaller than placeholder's name (currently maximum is 36, can be changed in
PatchScriptingAssemblyList.cs
) - Assembly not contained Monobehaviour, ScriptableObject and ManagedReference do not need to be added to
external.txt
. - If new mod is added or removed,
external.txt
should be modified before game loading. You can make a re-launch dialog box after user loads mod for first time.
#if IL2CPP_TARGET_ANDROID
void loadExternalAndroid()
{
//It's your game's persistent data path in android: com.{CompanyName}.{ProjectName}.
std::ifstream file("/storage/emulated/0/Android/data/com.AkiKurisu.IL2CPP_Mod/files/external.txt");
loadExternalFromStream(file);
}
#endif // IL2CPP_TARGET_ANDROID
void loadExternalWin(const char *data_path)
{
//Since engine send {GamePath}/il2cpp_data path to il2cpp, you can use it directly in Windows.
const char *filePath = hybridclr::ConcatNewString(data_path, "/external.txt");
std::ifstream file(filePath);
loadExternalFromStream(file);
}