Mega Tree API
Getting started
What you need installed, and the shortest path from an empty project to a node on screen.
Prerequisites
| You need | Why |
|---|---|
| .NET SDK 6.0 or newer | Only to build. The mod targets netstandard2.1, which is what Mono loads. |
| BepInEx 5 (Mono build) | Megastore Simulator is a Mono game. The IL2CPP build of BepInEx will not load. |
| Mega Tree 1.1.0 or newer | The API does not exist in 1.0.x. |
| A working BepInEx plugin | This page assumes your plugin already loads and logs something. |
If your plugin inherits from
BasePlugin and overrides Load(), you copied
an IL2CPP template - that is Supermarket Simulator, and it will never load here. In Mono the base
class is BaseUnityPlugin and the entry point is
Awake().
The failure is silent. No error, no log line, nothing in the plugin list. It reads exactly like a broken mod, which is why this is the first thing to check.
Four steps
1. Add MegaTree.dll to the references you already have
This is one extra reference on top of a normal Mono plugin project, not a
replacement for them. You still need BepInEx,
0Harmony, Assembly-CSharp and whichever
UnityEngine.* assemblies your code touches - all of them from the
game's Managed folder. Project setup has the
complete, working csproj.
Download the Mega Tree zip from Nexus, take MegaTree.dll out of
BepInEx/plugins/rodopoulos/, and add it with
Private=false:
<!-- IN ADDITION to your usual BepInEx / Harmony / Assembly-CSharp references. -->
<Reference Include="MegaTree">
<HintPath>C:\...\BepInEx\plugins\rodopoulos\MegaTree.dll</HintPath>
<Private>false</Private>
</Reference>Keep MegaTree.xml next to the dll and your editor shows the
documentation for every field as you type it. It ships in the same zip.
2. Declare the dependency
Without this attribute BepInEx may load your plugin before Mega Tree, and your registration call would hit a type that has not initialised yet.
[BepInPlugin("BigBoxes", "Big Boxes", "1.0.0")]
[BepInDependency(MegaTreeApi.ModGuid)]
public sealed class Plugin : BaseUnityPlugin { }3. Get your module and register
ForPlugin creates your sub-tab inside the Mods tab.
The second argument is the label on that sub-tab, and it is the only thing you ever say about
where your nodes appear.
private void Awake()
{
var tree = MegaTreeApi.ForPlugin("BigBoxes", "Big Boxes");
var handle = tree.Register(new UpgradeDefinition
{
Id = "bigboxes.capacity",
DisplayName = "Bigger Boxes",
MaxLevel = 3,
BaseCost = 1500,
Icon = UpgradeIcon.Builtin("package"),
DescribeLevel = lvl => $"+{lvl * 2} items per box",
});
// Register never throws. Check the handle instead.
if (!handle.Success) Logger.LogError(handle.Result.ToString());
}4. Implement the effect
Mega Tree stores the level. Making it mean something is your job. Read the level with
MegaTreeApi.GetLevel wherever the game asks the question:
[HarmonyPatch(typeof(SomeGameClass), "get_BoxCapacity")]
internal static class BoxCapacityPatch
{
private static void Postfix(ref int __result)
{
int lvl = MegaTreeApi.GetLevel("bigboxes.capacity");
if (lvl > 0) __result += lvl * 2;
}
}A Prefix writing to a ref parameter works in Mono. In Supermarket Simulator it installs fine and changes nothing, because the write never reaches the native call - a trap that costs people an afternoon there. Here the assemblies are real IL and the write lands.
Check it worked
- Close the game. BepInEx locks the dll while it runs, so a copy over a running game silently fails.
- Copy your dll into
BepInEx/plugins/. - Start the game, load a save, sit at the store computer and open Mega Tree.
- A Mods tab should be there, with your sub-tab inside it.
If it is not, the log will say why. Open
BepInEx/LogOutput.log and search for
[api] - every rejection is written there with your plugin guid and the
reason.
The Mods tab does not exist until a mod registers something, and an empty sub-tab is never drawn. If every one of your registrations failed, the tab does not appear either - which looks exactly like Mega Tree ignoring you. Check the log before assuming the API is broken.
Common first-run mistakes
| Symptom | Cause |
|---|---|
| Nothing loads, no log line at all | BepInEx 6 instead of 5, or a plugin built against IL2CPP. See Project setup. |
[api] registration of 'X' ... refused - id must be in 'prefix.name' form |
Ids must contain a dot and be lower case. See Registration. |
| Two Mega Tree versions load | You shipped MegaTree.dll with your mod. Set Private=false. |
TypeLoadException on your plugin |
The installed Mega Tree is older than 1.1.0. |
| Node shows but does nothing | You registered it but never wrote the effect. That part is always yours. |