In Game Console for Developers - Ijwu/PhoenixPointModLoader GitHub Wiki
Using the In-Game Console as a Developer
This page attempts to explain the console in more technical terms such that a developer may find use of it. It is intended for those with programming experience who are familiar with command-line interfaces.
Exposing Console Commands
Console commands are merely methods which are dynamically called within the Phoenix Point game code. They are annotated with the Base.Utils.GameConsole.ConsoleCommandAttribute
type. At startup the game will attempt to find all methods with this attribute within its own assembly. The game then collates and stores them for use later by the console.
One of the default mods used by PPML loads with Low
priority and reads all assemblies loaded in the AppDomain
and re-initializes the console command dictionary. (It does not touch already registered commands.)
If the method requires arguments then those may be supplied to the command within the console. The game attempts to automatically convert the given input into the types of your method parameters. All command definitions have the opportunity to define a Name
and Description
for their command (within the ConsoleCommandAttribute
). The Name
may be used to call the command, if null
then the method name is used. The Description
is used to provide a definition of the command behavior for use by other commands (e.g. help
command).
There are a few conditions for a method to be picked up by the in game console. The method must:
- Be
public
andstatic
. - Define an initial parameter implementing the interface
Base.Utils.GameConsole.IConsole
.- Every time the console calls your method it will supply this argument. Use it to output messages to the player or receive more input.
- Just using a parameter of
IConsole
is a good default.
- Define all other parameters as types which are defined in the console type conversion dictionary. (See Console Type Converters)
If any of the above conditions is unfulfilled then the method may simply not be recognized by the console.* See the [self decompiled] implementation of Base.Utils.GameConsole.ConsoleCommandAttribute
for details.
- These checks are not currently implemented in the PPML mod which loads mod supplied console commands. (Yet.)
Console Log
The game automatically logs all console output to a file in the base game directory under the name Console.log
.
Example
Example source for a new console command:
public class ExampleClass
{
[ConsoleCommand(Command = "hello", Description = "Prints hello to the specified person.")]
public static void SayHello(IConsole console, string name)
{
console.WriteLine($"Hello, {name}!");
}
}
The command may then be executed on the console using hello
. Here is an example execution and output:
> hello Ijwu
Hello, Ijwu!
Console Type Converters
All primitive types are converted automatically from string
using the .NET built-in conversion methods. No extra types are inherently converted.
Numeric types supported:
int
uint
long
ulong
short
ushort
float
double
byte
sbyte
String types are inherently supported.
bool
is supported but supports some extra logic. See the table below:
Input | Converted Value |
---|---|
any number >0 | true |
true | true |
0 | false |
false | false |