Skip to content

1. Exposed stuff

SomeRandomNoobKekeke edited this page Apr 27, 2026 · 5 revisions

By default ClearScript provides just basic language support
All real functionality is located in adapted c# objects explicitly exposed to js

What is exposed

  • host, xHost - magic, utils objects for interacting with C# types and objects, they are key, xHost is just better version of host, read about them here
  • JS - Exposes Methods for interacting with the engine
  • Console - Exposes Log, Warning, Error methods that writes in both consoles at once
  • ModInfo.Package - A variable that is temporarily set to the current package when js loads its scripts
  • ModInfo.FullPath - Full patch to the mod folder, also temporary
  • API - Contains various easy to use APIs like JSHook for patching the game with harmony, Console for adding console commands or Web for creating web servers
  • lib - mega object, contains all host assemblies and types except for extension types
  • BindingFlags - object containing all possible combinations of c# BindingFlags and FromInt() method if that's somehow not enough

Also there is:

  • [Obsolete] GetMethod(path) - global func that gets MethodBase by string path, so GetMethod("Barotrauma.GameMain.Update") == xHost.typeOf(lib.Barotrauma.GameMain).GetMethod("Update", lib.HarmonyLib.AccessTools.all)
  • setTimeout(jsfunc, delay) - There's no built-in setTimeout, this one is c# imposter that uses tasks under the hood
  • Every c# object has _Get() and _Set() reflection helpers

Clone this wiki locally