Available Callbacks

General

  • void Main() - called once when the plugin is loaded, enabled or reloaded.
  • void OnDisabled() - called when the plugin is disabled, removed or the game is closing.
  • void Render() - called on every game frame. You can use this function to render standalone UI windows. To determine how much time has passed since the last frame, use Time::Now.
  • void OnGameStateChanged(TM::GameState state) - called when the game state changes.
  • void OnCommandListChanged(CommandList@ prev, CommandList@ current, CommandListChangeReason reason) - called when current the command list changes. The callback provides the previous and new command list, as well as the reason for the change. You may hold a reference to the current command list if needed, but it is recommended that you reset the handle as soon as possible to avoid TMInterface from keeping the list in memory when it unloads.

    If a new command list was loaded, the current parameter will contain the new command list. You can then get the filename as well as the content of the list. A plugin can decide to do additional processing on the list. In this case, the plugin can set a new command list as the current one by using SetCurrentCommandList function. If the set call is made directly in the callback, you must prevent infinite recursion by saving state in the plugin and checking it when you get another callback. It is recommended to call SetCurrentCommandList outside of the function, for example in the Render callback.

    The current list may not be associated with any file (filename will be an empty string). In this case, the command list was created in the event of loading inputs from a validated replay or executing a timed command directly in the console without any input file being loaded. If the list is being cloned by the plugin, the new command list should be created accordingly (call empty constructor if the filename is empty and the path constructor otherwise).

    The current list will not be parsed yet at the time of the callback. To force parsing, call the Process method on the current list with the OnlyParse option in the callback.

  • PluginInfo@ GetPluginInfo() - called before Main(), this function should only return a PluginInfo object with information about the plugin. Any init logic should be contained within the Main() function, and not in this function. This function is required to be implemented.

Race

  • void OnRunStep(SimulationManager@ simManager) - called on every race step (when in normal race). Note that OnRunStep will be called before the race begins (simManager.RaceTime < 0) and after it ends (simManager.TickTime > simManager.RaceTime).

Simulation

  • void OnSimulationBegin(SimulationManager@ simManager) - called when the simulation begins (when clicking the Validate button in the Replays menu).
  • void OnSimulationStep(SimulationManager@ simManager, bool userCancelled) - called on every simulation step. userCancelled switches to true and if the user cancelled the simulation. The value stays true until the next OnSimulationBegin call.
  • void OnSimulationEnd(SimulationManager@ simManager, SimulationResult result) - called when the simulation ends (that matches the OnSimulationBegin call).

Race & simulation events

  • void OnCheckpointCountChanged(SimulationManager@ simManager, int current, int target) - called when a new checkpoint is passed. Inspect simManager.PlayerInfo.CheckpointStates to get which checkpoint has been just passed. While the condition current == target can be used to determine if the race has finished, it is recommended to evaluate simManager.PlayerInfo.RaceFinished instead.

  • void OnLapCountChanged(SimulationManager@ simManager, int current, int target) - called when a new lap is passed.