Kodi Documentation 18.0
Kodi is an open source media player and entertainment hub.
kodi_game_dll.h File Reference
#include "kodi_game_types.h"

Functions

GAME_ERROR LoadGame (const char *url)
 Load a game. More...
 
GAME_ERROR LoadGameSpecial (SPECIAL_GAME_TYPE type, const char **urls, size_t urlCount)
 Load a game that requires multiple files. More...
 
GAME_ERROR LoadStandalone (void)
 Begin playing without a game file. More...
 
GAME_ERROR UnloadGame (void)
 Unload the current game. More...
 
GAME_ERROR GetGameTiming (game_system_timing *timing_info)
 Get timing information about the loaded game. More...
 
GAME_REGION GetRegion (void)
 Get region of the loaded game. More...
 
bool RequiresGameLoop (void)
 Return true if the client requires the frontend to provide a game loop. More...
 
GAME_ERROR RunFrame (void)
 Run a single frame for add-ons that use a game loop. More...
 
GAME_ERROR Reset (void)
 Reset the current game. More...
 
GAME_ERROR HwContextReset (void)
 Invalidates the current HW context and reinitializes GPU resources. More...
 
GAME_ERROR HwContextDestroy (void)
 Called before the context is destroyed. More...
 
bool HasFeature (const char *controller_id, const char *feature_name)
 Check if input is accepted for a feature on the controller. More...
 
game_input_topologyGetTopology ()
 Get the input topology that specifies which controllers can be connected. More...
 
void FreeTopology (game_input_topology *topology)
 Free the topology's resources. More...
 
void SetControllerLayouts (const game_controller_layout *controllers, unsigned int controller_count)
 Set the layouts for known controllers. More...
 
bool EnableKeyboard (bool enable, const char *controller_id)
 Enable/disable keyboard input using the specified controller. More...
 
bool EnableMouse (bool enable, const char *controller_id)
 Enable/disable mouse input using the specified controller. More...
 
bool ConnectController (bool connect, const char *port_address, const char *controller_id)
 Connect/disconnect a controller to a port on the virtual game console. More...
 
bool InputEvent (const game_input_event *event)
 Notify the add-on of an input event. More...
 
size_t SerializeSize (void)
 Get the number of bytes required to serialize the game. More...
 
GAME_ERROR Serialize (uint8_t *data, size_t size)
 Serialize the state of the game. More...
 
GAME_ERROR Deserialize (const uint8_t *data, size_t size)
 Deserialize the game from the given state. More...
 
GAME_ERROR CheatReset (void)
 Reset the cheat system. More...
 
GAME_ERROR GetMemory (GAME_MEMORY type, uint8_t **data, size_t *size)
 Get a region of memory. More...
 
GAME_ERROR SetCheat (unsigned int index, bool enabled, const char *code)
 Set a cheat code. More...
 
void __declspec (dllexport) get_addon(void *ptr)
 Called by Kodi to assign the function pointers of this add-on to pClient. More...
 

Function Documentation

◆ __declspec()

__declspec ( dllexport  )

Called by Kodi to assign the function pointers of this add-on to pClient.

Note that get_addon() is defined here, so it will be available in all compiled game clients.

◆ CheatReset()

GAME_ERROR CheatReset ( void  )

Reset the cheat system.

Returns
the error, or GAME_ERROR_NO_ERROR if the cheat system was reset

◆ ConnectController()

bool ConnectController ( bool  connect,
const char *  port_address,
const char *  controller_id 
)

Connect/disconnect a controller to a port on the virtual game console.

Parameters
connectTrue to connect a controller, false to disconnect
port_addressThe address of the port
controller_idThe controller ID if connecting, or unused if disconnecting
Returns
True if the controller was (dis-)connected to the port, false otherwise

The address is a string that allows traversal of the controller topology. It is formed by alternating port IDs and controller IDs separated by "/".

For example, assume that the topology represented in XML for Snes9x is:

<logicaltopology>
  <port type="controller" id="1">
    <accepts controller="game.controller.snes"/>
    <accepts controller="game.controller.snes.multitap">
      <port type="controller" id="1">
        <accepts controller="game.controller.snes"/>
      </port>
      <port type="controller" id="2">
        <accepts controller="game.controller.snes"/>
      </port>
      ...
    </accepts>
  </port>
</logicaltopology>

To connect a multitap to the console's first port, the multitap's controller info is set using the port address:

/1

To connect a SNES controller to the second port of the multitap, the controller info is next set using the address:

/1/game.controller.multitap/2

Any attempts to connect a controller to a port on a disconnected multitap will return false.

◆ Deserialize()

GAME_ERROR Deserialize ( const uint8_t data,
size_t  size 
)

Deserialize the game from the given state.

Parameters
dataA buffer containing the game's new state
sizeThe size of the buffer
Returns
the error, or GAME_ERROR_NO_ERROR if the game deserialized

◆ EnableKeyboard()

bool EnableKeyboard ( bool  enable,
const char *  controller_id 
)

Enable/disable keyboard input using the specified controller.

Parameters
enableTrue to enable input, false otherwise
controller_idThe controller ID if enabling, or unused if disabling
Returns
True if keyboard input was enabled, false otherwise

◆ EnableMouse()

bool EnableMouse ( bool  enable,
const char *  controller_id 
)

Enable/disable mouse input using the specified controller.

Parameters
enableTrue to enable input, false otherwise
controller_idThe controller ID if enabling, or unused if disabling
Returns
True if mouse input was enabled, false otherwise

◆ FreeTopology()

void FreeTopology ( game_input_topology topology)

Free the topology's resources.

Parameters
topologyThe topology returned by GetTopology()

◆ GetGameTiming()

GAME_ERROR GetGameTiming ( game_system_timing timing_info)

Get timing information about the loaded game.

Parameters
[out]timing_infoThe info structure to fill
Returns
the error, or GAME_ERROR_NO_ERROR if info was filled

◆ GetMemory()

GAME_ERROR GetMemory ( GAME_MEMORY  type,
uint8_t **  data,
size_t *  size 
)

Get a region of memory.

Parameters
typeThe type of memory to retrieve
dataSet to the region of memory; must remain valid until UnloadGame() is called
sizeSet to the size of the region of memory
Returns
the error, or GAME_ERROR_NO_ERROR if data was set to a valid buffer

◆ GetRegion()

GAME_REGION GetRegion ( void  )

Get region of the loaded game.

Returns
the region, or GAME_REGION_UNKNOWN if unknown or no game is loaded

◆ GetTopology()

game_input_topology * GetTopology ( )

Get the input topology that specifies which controllers can be connected.

Returns
The input topology, or null to use the default

If this returns non-null, topology must be freed using FreeTopology().

If this returns null, the topology will default to a single port that can accept all controllers imported by addon.xml. The port ID is set to the DEFAULT_PORT_ID constant.

◆ HasFeature()

bool HasFeature ( const char *  controller_id,
const char *  feature_name 
)

Check if input is accepted for a feature on the controller.

If only a subset of the controller profile is used, this can return false for unsupported features to not absorb their input.

If the entire controller profile is used, this should always return true.

Parameters
controller_idThe ID of the controller profile
feature_nameThe name of a feature in that profile
Returns
true if input is accepted for the feature, false otherwise

◆ HwContextDestroy()

GAME_ERROR HwContextDestroy ( void  )

Called before the context is destroyed.

Resources can be deinitialized at this step.

Returns
the error, or GAME_ERROR_NO_ERROR if the HW context was destroyed

◆ HwContextReset()

GAME_ERROR HwContextReset ( void  )

Invalidates the current HW context and reinitializes GPU resources.

Any GL state is lost, and must not be deinitialized explicitly.

Returns
the error, or GAME_ERROR_NO_ERROR if the HW context was reset

◆ InputEvent()

bool InputEvent ( const game_input_event event)

Notify the add-on of an input event.

Parameters
eventThe input event
Returns
true if the event was handled, false otherwise

◆ LoadGame()

GAME_ERROR LoadGame ( const char *  url)

Load a game.

Parameters
urlThe URL to load

return the error, or GAME_ERROR_NO_ERROR if the game was loaded

◆ LoadGameSpecial()

GAME_ERROR LoadGameSpecial ( SPECIAL_GAME_TYPE  type,
const char **  urls,
size_t  urlCount 
)

Load a game that requires multiple files.

Parameters
typeThe game type
urlsAn array of urls
urlCountThe number of urls in the array
Returns
the error, or GAME_ERROR_NO_ERROR if the game was loaded

◆ LoadStandalone()

GAME_ERROR LoadStandalone ( void  )

Begin playing without a game file.

If the add-on supports standalone mode, it must add the <supports_standalone> tag to the extension point in addon.xml:

<supports_no_game>false</supports_no_game>
Returns
the error, or GAME_ERROR_NO_ERROR if the game add-on was loaded

◆ RequiresGameLoop()

bool RequiresGameLoop ( void  )

Return true if the client requires the frontend to provide a game loop.

The game loop is a thread that calls RunFrame() in a loop at a rate determined by the playback speed and the client's FPS.

Returns
true if the frontend should provide a game loop, false otherwise

◆ Reset()

GAME_ERROR Reset ( void  )

Reset the current game.

Returns
the error, or GAME_ERROR_NO_ERROR if the game was reset

◆ RunFrame()

GAME_ERROR RunFrame ( void  )

Run a single frame for add-ons that use a game loop.

Returns
the error, or GAME_ERROR_NO_ERROR if there was no error

◆ Serialize()

GAME_ERROR Serialize ( uint8_t data,
size_t  size 
)

Serialize the state of the game.

Parameters
dataThe buffer receiving the serialized game data
sizeThe size of the buffer
Returns
the error, or GAME_ERROR_NO_ERROR if the game was serialized into the buffer

◆ SerializeSize()

size_t SerializeSize ( void  )

Get the number of bytes required to serialize the game.

Returns
the number of bytes, or 0 if serialization is not supported

◆ SetCheat()

GAME_ERROR SetCheat ( unsigned int  index,
bool  enabled,
const char *  code 
)

Set a cheat code.

Parameters
index
enabled
code
Returns
the error, or GAME_ERROR_NO_ERROR if the cheat was set

◆ SetControllerLayouts()

void SetControllerLayouts ( const game_controller_layout controllers,
unsigned int  controller_count 
)

Set the layouts for known controllers.

Parameters
controllersThe controller layouts
controller_countThe number of items in the array

After loading the input topology, the frontend will call this with controller layouts for all controllers discovered in the topology.

◆ UnloadGame()

GAME_ERROR UnloadGame ( void  )

Unload the current game.

Returns
the error, or GAME_ERROR_NO_ERROR if the game was unloaded

Unloads a currently loaded game