Extending in C#

The typed modules (PM.Parts, PM.Planets, and the rest) are not special. They are built on the same public extension points a C# mod can use to add its own. If you want patch authors to be able to patch a kind of content PatchManager does not cover, or to give them domain-aware helpers like the stock modules have, you do it from a C# mod.

This is C# mod territory, not Lua patch territory. If you only write patches, you do not need this section. It is here for mod authors building the tools other patch authors use.

The extension points

There are three, in rough order of how often you would use them:

  • Converters let you patch a kind of content PatchManager does not yet cover. A converter turns an asset's JSON into the value a patch callback edits and back again. Add one and Lua authors can patch that content through PM:Patch("YourName", ...).

  • Module data adapters give a part-module data type typed Lua access, the way Data_Engine gets the engineModes helper. Register one for your own data types so authors get a strongly-typed wrapper instead of raw JSON.

  • Submodules and entry points put a typed PM.YourThing:Patch(...) on the PM table and a matching Patching.Mod.PatchYourThing(...) in C#, so your content gets the same convenience the stock modules have.

How they fit together

A converter is the foundation: it decides what value a patch gets. A module data adapter refines the value the parts converter produces for one data type. A submodule is a thin convenience layer that fills in your converter and label so authors do not type them. You can add just a converter and stop there, or layer adapters and a submodule on top for a polished result. The stock parts module is all three together, and it is the reference to copy.

Throughout, the bridge that makes a C# type usable from Lua is the [MoonSharpUserData] attribute, covered on the converters page.