Developer Harmony IL2CPP
Patch style, performance rules, and IL2CPP pitfalls. (Oxide equivalent: “Publicizer” + “Using Decompiler” + “Best Practices”, adapted to Unity 6000 IL2CPP.)
Patch style
Section titled “Patch style”- One task per patch class, deriving from
SafePatch; explicitPatchAll(never blanket-apply surprises). try/catchinside every patch;true/falseprefix semantics (returnfalseskips the original — use deliberately).- Small defensive Prefix/Postfix pairs; emit events (
greg.RACK.*,greg.SYSTEM.ButtonCheckOut, …) instead of duplicating logic. - Never hand-roll method lookup:
gregCore.Core.Mods.GregPatches.TryPatchPrefix/TryPatchPostfix(harmony, type, name, holder, patch, logTag)warns + returns false when the target is missing (game update) instead of throwing. - Representative classes (
src/gregCore.Patches/):HardwareIdPersistencePatch,IncompatibleModGuard,RackPatch,SaveSystemPatch,SaveManagerPatch,NetworkMapPatch,CablePositionsPatch,TimePatch,LoadingScreenPatch,PlayerPatch,ShopPatch,ServerPatch,KeybindPatches,SettingsUiBridgePatch,InputControllerPatch,RackPlacementPatch.
Performance rules (measured, not stylistic)
Section titled “Performance rules (measured, not stylistic)”- No per-frame reflection. Cache
Type.GetType/MethodInfoonce. - No
FindObjectsOfTypeinOnUpdate. Cache holders; throttle scans (tiers: 0.1 s / 1 s / 2 s / 30 s). - Event-state, not polling where possible (
PortSpeedMemorypattern); visual animators (RgbAnimator) track slots instead of rescanning. - Route bursts through
GregOperationQueue; background budgets viaGregPerformanceGovernor/GregResourceMonitor/GregPerformancePatches(incl.WorldCanvasCuller, technician/footstep/indicator throttles).
IL2CPP pitfalls
Section titled “IL2CPP pitfalls”Il2CppReferenceArray: always copy/extend properly (shop rows, dropdown items viaIl2CppSystem.Collections.Generic.List<string>).Nullable<Color>needs explicit handling;renderer.materialsclones — mutate the clone.- Never cache Il2Cpp objects long-term (GC moves them); re-resolve via inventory UIDs.
- Inactive
DontDestroyOnLoadholders for state you must keep;DelegateSupport.ConvertDelegatefor managed→Il2Cpp callbacks. OnGUIis stripped and there is noEventSystem— UIToolkit +GregClickRouteronly (Developer UI Panels HUD).
After a game update
Section titled “After a game update”- Run the game once with MelonLoader; re-copy
Il2CppAssemblies+net6intoreferences/. tools/GameApiGenerator/regenerate.sh→ re-checksrc/gregCore.GameApi/Generated/.scripts/Generate-GregHooksFromIl2CppDump.ps1→ reviewgame_hooks.json→ curateframework/greg_hooks.json.scripts/validate_contracts.py+scripts/check-coverage.sh+ fulldotnet test.- Vanilla-first test: no mods → game loads → enable yours.