The game's classes
local UE = CS.UnityEngine -- any class by full name local go = UE.GameObject("name") -- calling a class runs its constructor local image = go:AddComponent(UE.UI.Image) -- a class passed for a System.Type becomes that type image.color = { 1, 1, 1, 0.5 } -- structs are tables, by field name or in order print(image.transform.anchoredPosition.x) -- fields, properties and methods by name
Overloads are picked from the arguments. To hook an overloaded method, pass its parameter count or type names: hook(Class, "Name", 2, callbacks) or hook(Class, "Name", { "System.Single", "*" }, callbacks).
Numbers, booleans and strings convert both ways, enums are integers, arrays index from 0 like in C#.
Unity calls are only safe on the main thread: in on("update"), in hooks on game methods, and at load.
Unity objects a mod creates (constructors, Object.Instantiate) are destroyed before every reload. on("unload") is only needed for anything else.
CS
table<string, any>
Every class of the game and of Unity, by full name: CS.UnityEngine.GameObject, CS.ScoreControl.
HookCallbacks
| Field | Type | |
|---|---|---|
before? | fun(self: Unity, ...) | |
after? | fun(self: Unity, ...): any | returning a value replaces the result |
hook(class, name, callbacks) hook(class, name, params, callbacks)
Runs functions around a game method: before gets its arguments, after its arguments then its result.
hook(CS.ScoreControl, "Perfect", { before = function(self, noteCode, judgeTime) end, after = function(self, noteCode, judgeTime, pos, flag, result) end, })
| Parameter | Type | |
|---|---|---|
class | Unity | |
name | string | |
callbacks | HookCallbacks |
Returns integer (id): for unhook
unhook(id)
local id = hook(CS.ScoreControl, "Perfect", { after = function() print("perfect") end }) unhook(id) -- the method runs as the game wrote it again
| Parameter | Type | |
|---|---|---|
id | integer | what hook returned |