Skip to content

Capabilities

Lukas22041 edited this page Aug 28, 2026 · 2 revisions

PatchLib has a variety of functionality, but it mainly revolves around bytecode modification. Oftentimes when modding Starsector, you may find yourself thinking, "If only there was a way to modify this," because Starsector's API is not comprehensive enough for what you need.

PatchLib enables exactly this, letting you create patches that modify existing game code. Those changes are applied only while the game runs and do not require modifying the game's jar.

The library offers the following ways to modify code:

  • Adding code at the start & end of a method.
  • Replacing or modifying the return value of a method.
  • Replacing or modifying the parameters passed to a method.
  • Skipping a method's original code and inserting your own.
  • Redirecting method calls, field reads, field writes and object construction within a method's body.

With these tools, you can insert code right where you need it. For example, you may want to create your own listener where Starsector doesn't have one yet, or make a currently hardcoded value modifiable as a stat.

Scope

PatchLib can target most game code. This means it can patch both Starsector code and code added by mods. This can be useful for broader patches, like those that should modify all hullmod plugins. Some limitations in scope will be discussed on a later page.

When not to use it?

Starsector already has a rich API. If Starsector already lets you do something without much resistance, you should use that functionality. While stable on their own, too many mods with too many massive patches can become an instability problem. This is a very powerful tool, so you should try to use it carefully and in a targeted manner.

Clone this wiki locally