LethalAPI Terminal

版本 v1.0.1·更新於 2024-01-09

A fully fledged modding API for everything to do with the on-ship Terminal. Including custom commands, interactions, terminal overhauls, conditional command overrides, and more.

模組介紹 作者原文

LethalAPI.Terminal

Terminal Commands API for the Lethal Company Modding API

Misc Changes

This mod makes some changes to how the terminal works, that isn't fully integral to custom commands.

These changes are as such:

  • Reduces the delay after entering the terminal before you can type by 80%
  • You ever open the terminal and start typing, even hearing the keyboard sound, but it doesn't write anything? This fixes that.
  • Disable scrolling to the top of the terminal on every command execution
  • This now only happens when a command clears the screen.
  • Trims newlines from the start of command responses
  • The game force adds newlines to the start of commands, which causes issues for commands that don't clear the terminal.

Creating terminal commands

Terminal commands are declared as annotated methods. E.g.,

[TerminalCommand("Ping"), CommandInfo("Test command")]

public string PingCommand()

{

return "Pong!";

}

All terminal commands are annotated with the TerminalCommand Attribute, and optionally, the CommandInfo Attribute.

The CommandInfo attribute attaches command metadata and enrolls the command to be displayed in the help command.

You can also attach access control attributes, e.g., AllowedCaller to specify who can execute a command and when. More on this later.

Registering Commands

All commands have to be registered to this library. Registering commands can be done through the CommandRegistry API. E.g.,

private TerminalModRegistry Commands;

public void Awake()

{

Commands = TerminalRegistry.CreateModRegistry();

Commands.RegisterFrom(this); // Register commands from the plugin class

Commands.RegisterFrom(AnotherObject); // Register commands from another instance

Commands.RegisterFrom(); // Activate and register commands from a type

}

You can also deregister commands by calling TerminalModRegistry.Deregister().

Handling arguments

All arguments are injected into the method, either parsed from the user input, or sourced from the execution context. E.g.,

[TerminalCommand("RickRoll")]

public string RickRollCommand(Terminal caller, [RemainingText] string text)

{

// Echoes the user's message back to them, and rickrolls them

caller.PlayVideoFile(RickrollVideoPath);

return text;

}

[TerminalCommand("Multiply")]

public int MultiplyCommand(int a, int b)

{

return a * b;

}

Notice how commands don't need to return a string but can return anything. You can return your own TerminalNode, which is how the game itself handles command responses, or you can return anything, and it will be converted to a string.

Additionally, if you return null, execution will fall through to the next valid command handler. More on this later.

You can even parse some extra types such as PlayerControllerB, which will be parsed from Steam64ID, or player name. Argument injection is a useful tool to reduce boilerplate and create command overloads.

You can inject as many arguments as you want, and the method will only be executed when all specified arguments can be provided, either from context, or parsed from user input. Generally, you will never need to manually parse basic arguments yourself. However, if you do want to handle argument parsing yourself, you can inject either string or ArgumentStream.

Command Overloading

When a player runs a command, the first step in this process is selecting candidate commands. All commands registered with the same command name, and matching signatures can be evaluated. These commands with matching/compatible signatures will be executed in descending order of priority, and then argument count.

So a command with more arguments will take priority over a command with less arguments. However all these arguments still must be valid and parsed from user input. Meaning you can create command patterns such as:

[TerminalCommand("BuyArtefact")]

public string BuyArtefactCommand()

{

return $"Available Artefacts:\n"

+ FormatAvailableArtefacts();

}

[TerminalCommand("BuyArtefact")]

public string BuyArtefactCommand(st

安裝與使用 安裝:BepInEx 外掛

  1. 本站下載的壓縮包就是模組本體,通常是 BepInEx 外掛(解壓後得到 .dll 或外掛資料夾)。
  2. 建議流程:用社群模組管理器(如 r2modman)選中本遊戲後匯入該模組,管理器會自動裝好 BepInEx 前置並處理依賴。
  3. 手動流程:先在遊戲目錄裝好 BepInEx 載入器,再把解壓出的 .dll 或外掛資料夾放進 BepInEx/plugins/。
  4. 啟動遊戲,BepInEx 控制台會列印載入日誌;確認這個模組出現在日誌裡即為安裝成功。

帶「前置依賴」的模組需要一併安裝,否則不會載入。功能開關通常在遊戲內或外掛自帶的設定檔裡調整。

前置依賴

下面這些內容需要先安裝,否則該模組不會生效:

BepInEx-BepInExPack

檔案與校驗

檔案名稱
LethalAPI_Terminal-1.0.1.zip
檔案大小
44.8 KiB