Mega Tree API
Mega Tree API
Put your own upgrades in the Mega Tree. You describe the node and write the effect; Mega Tree draws it, prices it, gates it, saves it and translates it.
What this is
Mega Tree is an upgrade tree that lives as an app on the store computer in Megastore Simulator. Since version 1.1.0 it is also a host: any BepInEx mod can register its own upgrade lines and they appear in the tree alongside the built-in ones.
The split is deliberate and it is the whole point of the API:
| Your mod | Mega Tree |
|---|---|
| Names the upgrade and its icon | Draws the node, the branch and the connectors |
| Says how many levels there are | Chains the levels and enforces buying in order |
| Says what each level costs | Charges the player and handles selling back, 50% by default |
| Writes the one-line effect text | Shows it on the hover card |
| Decides when the node unlocks | Greys it out and shows your reason until then |
| Implements the effect | Saves the level per save slot and tells you when it changes |
If you have modded Supermarket Simulator, everything you know about the API carries over and everything you know about the platform does not. There is no Il2CppInterop here, no ClassInjector, no (IntPtr ptr) constructor - a MonoBehaviour is just a MonoBehaviour, and writing a static field does not crash the game.
The one thing that bites everyone: BepInEx 5, not 6. The wrong one fails silently. Project setup has the csproj that works.
Hello world
This is a complete, working registration. Two calls.
using BepInEx;
using MegaTree.Api;
[BepInPlugin("BigBoxes", "Big Boxes", "1.0.0")]
[BepInDependency(MegaTreeApi.ModGuid)]
public sealed class Plugin : BaseUnityPlugin
{
private void Awake()
{
// "Big Boxes" is the label of your own sub-tab inside the Mods tab.
var tree = MegaTreeApi.ForPlugin("BigBoxes", "Big Boxes");
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",
});
}
}That gives the player a three-level line, priced 1500 / 2700 / 4860, saved per save slot, sellable, and greyed out when they cannot afford it. What it does not do is make boxes bigger - that part is yours, and Events is where it goes.
Mega Tree stores a number and tells you when it changes. It has no idea what "bigger boxes" means. Every node in the Mods tab works this way, including the ones in the example mod.
What you get for free
- The whole interface - node circles, branch colours, connector lines, hover card, hold-to-buy ring, drag, scroll and zoom.
- Buying and selling - affordability checks, the money transaction, and selling a level back for 50% of what it cost - or whatever rate your node declares.
- Per-slot saving - and levels are kept even while your mod is uninstalled, so a player who removes your mod and puts it back gets their progress back (how that works).
- Translation - into whatever languages the game offers, falling back to English and then to the raw key.
- Gating - your predicate decides, plus an optional store level requirement. Mega Tree does the greying out, the caching and the "why is this locked" line.
What it will not do
- Create a new top-level tab. Every registered node lives in the Mods tab, in your sub-tab. See The Mods tab.
- Run your effect every frame.
Applyfires about twice a second; for values the game rewrites constantly you patch the getter yourself. - Guess your effect from the numbers.
DescribeLevelis what the player reads, and nothing checks that it matches what your code does.