Skip to content

1. Exposed stuff

SomeRandomNoobKekeke edited this page Apr 25, 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
  • modlib - contains all c# mod assemblies, including JSForBarotrauma

There's also a few methods added on JS side:

  • 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), it can accept BindingFlags as second arg, but you can't combine them naturally in js, combinable flags is still wip
  • setTimeout(jsfunc, delay) - There's no built-in setTimeout, this one is c# imposter that uses tasks under the hood

Clone this wiki locally