// ============================================================================ // RynthCore.Loader.dll - native loader (docs/UNLOADABLE_ENGINE_PLAN.md, Phase 1) // // Injected into acclient.exe by RynthCore.Injector / the launcher, which call the // RynthCoreInit export on a remote thread (same contract as the old NativeAOT loader). // // Two engine hosts, chosen by looking at Runtime\RynthCore.Engine.dll: // - NativeAOT engine (a native DLL exporting RynthCoreEngineInit): staged to // .engine_loads\, LoadLibrary'd, never freed. Today's behaviour. // - Managed engine (a PE with a CLR header): the loader starts CoreCLR once from // Runtime\dotnet\ and hands the engine to RynthCore.Shim.dll (default ALC), which // loads each generation into a collectible AssemblyLoadContext and unloads it on // reload, so a reload gives its memory back. // // Either way the loader owns the reload event, the file watcher, the address-space // guard, the reload cap (MaxHotReloads per client) and a MinHook facade (Hooks.c): // every hook is installed once, through a permanent stub, and a reload only re-points // the stub. For the managed engine it also sets up CoreCLR's crash dumps (Logs\dumps). // ============================================================================ #include "Loader.h" #include #include #include #define ENGINE_DLL_NAME "RynthCore.Engine.dll" #define ENGINE_INIT_EXPORT "RynthCoreEngineInit" #define ENGINE_SHUTDOWN_EXPORT "RynthCoreShutdown" #define ENGINE_REFUSED_EXPORT "RynthCoreReloadRefused" #define ENGINE_MAXRELOADS_EXPORT "RynthCoreMaxHotReloads" #define ENGINE_CAPPED_EXPORT "RynthCoreReloadCapped" #ifndef LOG_DIR // the offline tests (tools\Loader*Tests) log into their own folder #define LOG_DIR "C:\\Games\\RynthCore\\Logs" #define LOG_PARENT "C:\\Games\\RynthCore" #endif #define STAGING_SUBDIR ".engine_loads" // Hot reloads one client takes before it refuses the rest (until it restarts). The engine // says the real number (engine.json MaxHotReloads, RynthCoreMaxHotReloads export); this is // for an engine without the export. After 4+ reloads in one process, clients died with // CoreCLR fatal error 0x80131506 at coreclr+0x256E19 (2026-10-08..10, gens 5-6 or the 4th // reload itself) although every generation unloaded and address space stayed flat: treated // as a CoreCLR limit on repeated collectible loads, so the loader stops short of it. #define DEFAULT_MAX_HOT_RELOADS 3 // CoreCLR's own crash dump (createdump.exe, DOTNET_DbgEnableMiniDump): clr__