Kodi Development 22.0
for Binary and Script based Add-Ons
 
All Classes Functions Variables Typedefs Enumerations Enumerator Modules Pages
Loading...
Searching...
No Matches
Game.h
1/*
2 * Copyright (C) 2014-2025 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9#pragma once
10
11#include "../AddonBase.h"
12#include "../c-api/addon-instance/game.h"
13
14#include <algorithm>
15
16#ifdef __cplusplus
17
18namespace kodi
19{
20namespace addon
21{
22
23//==============================================================================
32
33//==============================================================================
38
39//==============================================================================
47{
48public:
50 explicit GameControllerLayout() = default;
51 GameControllerLayout(const game_controller_layout& layout) : controller_id(layout.controller_id)
52 {
53 provides_input = layout.provides_input;
54 for (unsigned int i = 0; i < layout.digital_button_count; ++i)
55 digital_buttons.emplace_back(layout.digital_buttons[i]);
56 for (unsigned int i = 0; i < layout.analog_button_count; ++i)
57 analog_buttons.emplace_back(layout.analog_buttons[i]);
58 for (unsigned int i = 0; i < layout.analog_stick_count; ++i)
59 analog_sticks.emplace_back(layout.analog_sticks[i]);
60 for (unsigned int i = 0; i < layout.accelerometer_count; ++i)
61 accelerometers.emplace_back(layout.accelerometers[i]);
62 for (unsigned int i = 0; i < layout.key_count; ++i)
63 keys.emplace_back(layout.keys[i]);
64 for (unsigned int i = 0; i < layout.rel_pointer_count; ++i)
65 rel_pointers.emplace_back(layout.rel_pointers[i]);
66 for (unsigned int i = 0; i < layout.abs_pointer_count; ++i)
67 abs_pointers.emplace_back(layout.abs_pointers[i]);
68 for (unsigned int i = 0; i < layout.motor_count; ++i)
69 motors.emplace_back(layout.motors[i]);
70 }
72
74 std::string controller_id;
75
79 bool provides_input{false};
80
82 std::vector<std::string> digital_buttons;
83
85 std::vector<std::string> analog_buttons;
86
88 std::vector<std::string> analog_sticks;
89
91 std::vector<std::string> accelerometers;
92
94 std::vector<std::string> keys;
95
97 std::vector<std::string> rel_pointers;
98
100 std::vector<std::string> abs_pointers;
101
103 std::vector<std::string> motors;
104};
105
106//------------------------------------------------------------------------------
107
108//==============================================================================
117class ATTR_DLL_LOCAL CInstanceGame : public IAddonInstance
118{
119public:
120 //============================================================================
126
127 //============================================================================
160 CInstanceGame() : IAddonInstance(IInstanceInfo(CPrivateBase::m_interface->firstKodiInstance))
161 {
162 if (CPrivateBase::m_interface->globalSingleInstance != nullptr)
163 {
164 throw std::logic_error(
165 "kodi::addon::CInstanceGame: Cannot create more than one game instance!");
166 }
167 SetAddonStruct(CPrivateBase::m_interface->firstKodiInstance);
168 CPrivateBase::m_interface->globalSingleInstance = this;
169 }
170 //----------------------------------------------------------------------------
171
172 //============================================================================
175 ~CInstanceGame() override = default;
176 //----------------------------------------------------------------------------
177
178 //============================================================================
186 std::string GameClientDllPath() const { return m_instanceData->props->game_client_dll_path; }
187 //----------------------------------------------------------------------------
188
189 //============================================================================
199 bool ProxyDllPaths(std::vector<std::string>& paths)
200 {
201 for (unsigned int i = 0; i < m_instanceData->props->proxy_dll_count; ++i)
202 {
203 if (m_instanceData->props->proxy_dll_paths[i] != nullptr)
204 paths.emplace_back(m_instanceData->props->proxy_dll_paths[i]);
205 }
206 return !paths.empty();
207 }
208 //----------------------------------------------------------------------------
209
210 //============================================================================
223 bool ResourceDirectories(std::vector<std::string>& dirs)
224 {
225 for (unsigned int i = 0; i < m_instanceData->props->resource_directory_count; ++i)
226 {
227 if (m_instanceData->props->resource_directories[i] != nullptr)
228 dirs.emplace_back(m_instanceData->props->resource_directories[i]);
229 }
230 return !dirs.empty();
231 }
232 //----------------------------------------------------------------------------
233
234 //============================================================================
246 std::string ProfileDirectory() const { return m_instanceData->props->profile_directory; }
247 //----------------------------------------------------------------------------
248
249 //============================================================================
257 bool SupportsVFS() const { return m_instanceData->props->supports_vfs; }
258 //----------------------------------------------------------------------------
259
260 //============================================================================
270 bool Extensions(std::vector<std::string>& extensions)
271 {
272 for (unsigned int i = 0; i < m_instanceData->props->extension_count; ++i)
273 {
274 if (m_instanceData->props->extensions[i] != nullptr)
275 extensions.emplace_back(m_instanceData->props->extensions[i]);
276 }
277 return !extensions.empty();
278 }
279 //----------------------------------------------------------------------------
280
282
283 //--==----==----==----==----==----==----==----==----==----==----==----==----==--
284
285 //============================================================================
304
305 //============================================================================
312 virtual GAME_ERROR LoadGame(const std::string& url) { return GAME_ERROR_NOT_IMPLEMENTED; }
313 //----------------------------------------------------------------------------
314
315 //============================================================================
323 virtual GAME_ERROR LoadGameSpecial(SPECIAL_GAME_TYPE type, const std::vector<std::string>& urls)
324 {
326 }
327 //----------------------------------------------------------------------------
328
329 //============================================================================
340 //----------------------------------------------------------------------------
341
342 //============================================================================
350 //----------------------------------------------------------------------------
351
352 //============================================================================
360 {
362 }
363 //----------------------------------------------------------------------------
364
365 //============================================================================
371 //----------------------------------------------------------------------------
372
373 //============================================================================
381 virtual bool RequiresGameLoop() { return false; }
382 //----------------------------------------------------------------------------
383
384 //============================================================================
390 //----------------------------------------------------------------------------
391
392 //============================================================================
398 //----------------------------------------------------------------------------
399
400 //==========================================================================
406 void CloseGame(void) { m_instanceData->toKodi->CloseGame(m_instanceData->toKodi->kodiInstance); }
407 //----------------------------------------------------------------------------
408
409 //============================================================================
420 class CStream
421 {
422 public:
423 CStream() = default;
424
425 CStream(const game_stream_properties& properties) { Open(properties); }
426
427 ~CStream() { Close(); }
428
429 //==========================================================================
439 bool Open(const game_stream_properties& properties)
440 {
441 if (!CPrivateBase::m_interface->globalSingleInstance)
442 return false;
443
444 if (m_handle)
445 {
446 kodi::Log(ADDON_LOG_INFO, "kodi::addon::CInstanceGame::CStream already reopened");
447 Close();
448 }
449
451 *static_cast<CInstanceGame*>(CPrivateBase::m_interface->globalSingleInstance)
452 ->m_instanceData->toKodi;
453 m_handle = cb.OpenStream(cb.kodiInstance, &properties);
454 return m_handle != nullptr;
455 }
456 //--------------------------------------------------------------------------
457
458 //==========================================================================
464 void Close()
465 {
466 if (!m_handle || !CPrivateBase::m_interface->globalSingleInstance)
467 return;
468
470 *static_cast<CInstanceGame*>(CPrivateBase::m_interface->globalSingleInstance)
471 ->m_instanceData->toKodi;
472 cb.CloseStream(cb.kodiInstance, m_handle);
473 m_handle = nullptr;
474 }
475 //--------------------------------------------------------------------------
476
477 //==========================================================================
491 bool GetBuffer(unsigned int width, unsigned int height, game_stream_buffer& buffer)
492 {
493 if (!m_handle || !CPrivateBase::m_interface->globalSingleInstance)
494 return false;
495
497 *static_cast<CInstanceGame*>(CPrivateBase::m_interface->globalSingleInstance)
498 ->m_instanceData->toKodi;
499 return cb.GetStreamBuffer(cb.kodiInstance, m_handle, width, height, &buffer);
500 }
501 //--------------------------------------------------------------------------
502
503 //==========================================================================
511 void AddData(const game_stream_packet& packet)
512 {
513 if (!m_handle || !CPrivateBase::m_interface->globalSingleInstance)
514 return;
515
517 *static_cast<CInstanceGame*>(CPrivateBase::m_interface->globalSingleInstance)
518 ->m_instanceData->toKodi;
519 cb.AddStreamData(cb.kodiInstance, m_handle, &packet);
520 }
521 //--------------------------------------------------------------------------
522
523 //==========================================================================
532 {
533 if (!m_handle || !CPrivateBase::m_interface->globalSingleInstance)
534 return;
535
537 *static_cast<CInstanceGame*>(CPrivateBase::m_interface->globalSingleInstance)
538 ->m_instanceData->toKodi;
539 cb.ReleaseStreamBuffer(cb.kodiInstance, m_handle, &buffer);
540 }
541 //--------------------------------------------------------------------------
542
543 //==========================================================================
551 bool IsOpen() const { return m_handle != nullptr; }
552 //--------------------------------------------------------------------------
553
554 private:
555 KODI_GAME_STREAM_HANDLE m_handle = nullptr;
556 };
557
558
560
561 //--==----==----==----==----==----==----==----==----==----==----==----==----==--
562
563 //============================================================================
579
580 //==========================================================================
589 {
590 return m_instanceData->toKodi->EnableHardwareRendering(m_instanceData->toKodi->kodiInstance,
591 &properties);
592 }
593 //----------------------------------------------------------------------------
594
595 //============================================================================
603 //----------------------------------------------------------------------------
604
605 //============================================================================
613
614 //============================================================================
624 {
625 return m_instanceData->toKodi->HwGetProcAddress(m_instanceData->toKodi->kodiInstance, sym);
626 }
627 //----------------------------------------------------------------------------
628
630
631 //--==----==----==----==----==----==----==----==----==----==----==----==----==--
632
633 //============================================================================
648
649 //============================================================================
661 virtual bool HasFeature(const std::string& controller_id, const std::string& feature_name)
662 {
663 return false;
664 }
665 //----------------------------------------------------------------------------
666
667 //============================================================================
678 virtual game_input_topology* GetTopology() { return nullptr; }
679 //----------------------------------------------------------------------------
680
681 //============================================================================
686 virtual void FreeTopology(game_input_topology* topology) {}
687 //----------------------------------------------------------------------------
688
689 //============================================================================
698 const std::vector<kodi::addon::GameControllerLayout>& controllers)
699 {
700 }
701 //----------------------------------------------------------------------------
702
703 //============================================================================
711 virtual bool EnableKeyboard(bool enable, const std::string& controller_id) { return false; }
712 //----------------------------------------------------------------------------
713
714 //============================================================================
722 virtual bool EnableMouse(bool enable, const std::string& controller_id) { return false; }
723 //--------------------------------------------------------------------------
724
725 //==========================================================================
769 virtual bool ConnectController(bool connect,
770 const std::string& port_address,
771 const std::string& controller_id)
772 {
773 return false;
774 }
775 //----------------------------------------------------------------------------
776
777 //============================================================================
784 virtual bool InputEvent(const game_input_event& event) { return false; }
785 //----------------------------------------------------------------------------
786
787 //============================================================================
800 {
801 return m_instanceData->toKodi->InputEvent(m_instanceData->toKodi->kodiInstance, &event);
802 }
803 //----------------------------------------------------------------------------
804
806
807 //--==----==----==----==----==----==----==----==----==----==----==----==----==--
808
809 //============================================================================
824
825 //============================================================================
830 virtual size_t SerializeSize() { return 0; }
831 //----------------------------------------------------------------------------
832
833 //============================================================================
841 virtual GAME_ERROR Serialize(uint8_t* data, size_t size) { return GAME_ERROR_NOT_IMPLEMENTED; }
842 //----------------------------------------------------------------------------
843
844 //============================================================================
852 virtual GAME_ERROR Deserialize(const uint8_t* data, size_t size)
853 {
855 }
856 //----------------------------------------------------------------------------
857
859
860 //--==----==----==----==----==----==----==----==----==----==----==----==----==--
861
862 //============================================================================
878
879 //============================================================================
885 //----------------------------------------------------------------------------
886
887 //============================================================================
896 virtual GAME_ERROR GetMemory(GAME_MEMORY type, uint8_t*& data, size_t& size)
897 {
899 }
900 //----------------------------------------------------------------------------
901
902 //============================================================================
911 virtual GAME_ERROR SetCheat(unsigned int index, bool enabled, const std::string& code)
912 {
914 }
915
916 //============================================================================
928 virtual GAME_ERROR RCGenerateHashFromFile(std::string& hash,
929 unsigned int consoleID,
930 const std::string& filePath)
931 {
933 }
934
935 //============================================================================
944 virtual GAME_ERROR RCGetGameIDUrl(std::string& url, const std::string& hash)
945 {
947 }
948
949 //============================================================================
960 virtual GAME_ERROR RCGetPatchFileUrl(std::string& url,
961 const std::string& username,
962 const std::string& token,
963 unsigned int gameID)
964 {
966 }
967
968 //============================================================================
984 virtual GAME_ERROR RCPostRichPresenceUrl(std::string& url,
985 std::string& postData,
986 const std::string& username,
987 const std::string& token,
988 unsigned int gameID,
989 const std::string& richPresence)
990 {
992 }
993
994 //============================================================================
1001 virtual GAME_ERROR RCEnableRichPresence(const std::string& script)
1002 {
1004 }
1005
1006 //============================================================================
1019 virtual GAME_ERROR RCGetRichPresenceEvaluation(std::string& evaluation, unsigned int consoleID)
1020 {
1022 }
1023
1024 //============================================================================
1032
1033 //----------------------------------------------------------------------------
1034
1036
1037private:
1038 void SetAddonStruct(KODI_ADDON_INSTANCE_STRUCT* instance)
1039 {
1040 instance->hdl = this;
1041
1042 instance->game->toAddon->LoadGame = ADDON_LoadGame;
1043 instance->game->toAddon->LoadGameSpecial = ADDON_LoadGameSpecial;
1044 instance->game->toAddon->LoadStandalone = ADDON_LoadStandalone;
1045 instance->game->toAddon->UnloadGame = ADDON_UnloadGame;
1046 instance->game->toAddon->GetGameTiming = ADDON_GetGameTiming;
1047 instance->game->toAddon->GetRegion = ADDON_GetRegion;
1048 instance->game->toAddon->RequiresGameLoop = ADDON_RequiresGameLoop;
1049 instance->game->toAddon->RunFrame = ADDON_RunFrame;
1050 instance->game->toAddon->Reset = ADDON_Reset;
1051
1052 instance->game->toAddon->HwContextReset = ADDON_HwContextReset;
1053 instance->game->toAddon->HwContextDestroy = ADDON_HwContextDestroy;
1054
1055 instance->game->toAddon->HasFeature = ADDON_HasFeature;
1056 instance->game->toAddon->GetTopology = ADDON_GetTopology;
1057 instance->game->toAddon->FreeTopology = ADDON_FreeTopology;
1058 instance->game->toAddon->SetControllerLayouts = ADDON_SetControllerLayouts;
1059 instance->game->toAddon->EnableKeyboard = ADDON_EnableKeyboard;
1060 instance->game->toAddon->EnableMouse = ADDON_EnableMouse;
1061 instance->game->toAddon->ConnectController = ADDON_ConnectController;
1062 instance->game->toAddon->InputEvent = ADDON_InputEvent;
1063
1064 instance->game->toAddon->SerializeSize = ADDON_SerializeSize;
1065 instance->game->toAddon->Serialize = ADDON_Serialize;
1066 instance->game->toAddon->Deserialize = ADDON_Deserialize;
1067
1068 instance->game->toAddon->CheatReset = ADDON_CheatReset;
1069 instance->game->toAddon->GetMemory = ADDON_GetMemory;
1070 instance->game->toAddon->SetCheat = ADDON_SetCheat;
1071
1072 instance->game->toAddon->RCGenerateHashFromFile = ADDON_RCGenerateHashFromFile;
1073 instance->game->toAddon->RCGetGameIDUrl = ADDON_RCGetGameIDUrl;
1074 instance->game->toAddon->RCGetPatchFileUrl = ADDON_RCGetPatchFileUrl;
1075 instance->game->toAddon->RCPostRichPresenceUrl = ADDON_RCPostRichPresenceUrl;
1076 instance->game->toAddon->RCEnableRichPresence = ADDON_RCEnableRichPresence;
1077 instance->game->toAddon->RCGetRichPresenceEvaluation = ADDON_RCGetRichPresenceEvaluation;
1078 instance->game->toAddon->RCResetRuntime = ADDON_RCResetRuntime;
1079
1080 instance->game->toAddon->FreeString = ADDON_FreeString;
1081
1082 m_instanceData = instance->game;
1083 m_instanceData->toAddon->addonInstance = this;
1084 }
1085
1086 // --- Game operations ---------------------------------------------------------
1087
1088 inline static GAME_ERROR ADDON_LoadGame(const AddonInstance_Game* instance, const char* url)
1089 {
1090 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)->LoadGame(url);
1091 }
1092
1093 inline static GAME_ERROR ADDON_LoadGameSpecial(const AddonInstance_Game* instance,
1094 SPECIAL_GAME_TYPE type,
1095 const char** urls,
1096 size_t urlCount)
1097 {
1098 std::vector<std::string> urlList;
1099 for (size_t i = 0; i < urlCount; ++i)
1100 {
1101 if (urls[i] != nullptr)
1102 urlList.emplace_back(urls[i]);
1103 }
1104
1105 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)
1106 ->LoadGameSpecial(type, urlList);
1107 }
1108
1109 inline static GAME_ERROR ADDON_LoadStandalone(const AddonInstance_Game* instance)
1110 {
1111 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)->LoadStandalone();
1112 }
1113
1114 inline static GAME_ERROR ADDON_UnloadGame(const AddonInstance_Game* instance)
1115 {
1116 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)->UnloadGame();
1117 }
1118
1119 inline static GAME_ERROR ADDON_GetGameTiming(const AddonInstance_Game* instance,
1120 game_system_timing* timing_info)
1121 {
1122 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)
1123 ->GetGameTiming(*timing_info);
1124 }
1125
1126 inline static GAME_REGION ADDON_GetRegion(const AddonInstance_Game* instance)
1127 {
1128 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)->GetRegion();
1129 }
1130
1131 inline static bool ADDON_RequiresGameLoop(const AddonInstance_Game* instance)
1132 {
1133 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)->RequiresGameLoop();
1134 }
1135
1136 inline static GAME_ERROR ADDON_RunFrame(const AddonInstance_Game* instance)
1137 {
1138 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)->RunFrame();
1139 }
1140
1141 inline static GAME_ERROR ADDON_Reset(const AddonInstance_Game* instance)
1142 {
1143 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)->Reset();
1144 }
1145
1146 // --- Hardware rendering operations -------------------------------------------
1147
1148 inline static GAME_ERROR ADDON_HwContextReset(const AddonInstance_Game* instance)
1149 {
1150 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)->HwContextReset();
1151 }
1152
1153 inline static GAME_ERROR ADDON_HwContextDestroy(const AddonInstance_Game* instance)
1154 {
1155 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)->HwContextDestroy();
1156 }
1157
1158 // --- Input operations --------------------------------------------------------
1159
1160 inline static bool ADDON_HasFeature(const AddonInstance_Game* instance,
1161 const char* controller_id,
1162 const char* feature_name)
1163 {
1164 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)
1165 ->HasFeature(controller_id, feature_name);
1166 }
1167
1168 inline static game_input_topology* ADDON_GetTopology(const AddonInstance_Game* instance)
1169 {
1170 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)->GetTopology();
1171 }
1172
1173 inline static void ADDON_FreeTopology(const AddonInstance_Game* instance,
1174 game_input_topology* topology)
1175 {
1176 static_cast<CInstanceGame*>(instance->toAddon->addonInstance)->FreeTopology(topology);
1177 }
1178
1179 inline static void ADDON_SetControllerLayouts(const AddonInstance_Game* instance,
1180 const game_controller_layout* controllers,
1181 unsigned int controller_count)
1182 {
1183 if (controllers == nullptr)
1184 return;
1185
1186 std::vector<GameControllerLayout> controllerList;
1187 controllerList.reserve(controller_count);
1188 for (unsigned int i = 0; i < controller_count; ++i)
1189 controllerList.emplace_back(controllers[i]);
1190
1191 static_cast<CInstanceGame*>(instance->toAddon->addonInstance)
1192 ->SetControllerLayouts(controllerList);
1193 }
1194
1195 inline static bool ADDON_EnableKeyboard(const AddonInstance_Game* instance,
1196 bool enable,
1197 const char* controller_id)
1198 {
1199 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)
1200 ->EnableKeyboard(enable, controller_id);
1201 }
1202
1203 inline static bool ADDON_EnableMouse(const AddonInstance_Game* instance,
1204 bool enable,
1205 const char* controller_id)
1206 {
1207 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)
1208 ->EnableMouse(enable, controller_id);
1209 }
1210
1211 inline static bool ADDON_ConnectController(const AddonInstance_Game* instance,
1212 bool connect,
1213 const char* port_address,
1214 const char* controller_id)
1215 {
1216 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)
1217 ->ConnectController(connect, port_address, controller_id);
1218 }
1219
1220 inline static bool ADDON_InputEvent(const AddonInstance_Game* instance,
1221 const game_input_event* event)
1222 {
1223 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)->InputEvent(*event);
1224 }
1225
1226 // --- Serialization operations ------------------------------------------------
1227
1228 inline static size_t ADDON_SerializeSize(const AddonInstance_Game* instance)
1229 {
1230 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)->SerializeSize();
1231 }
1232
1233 inline static GAME_ERROR ADDON_Serialize(const AddonInstance_Game* instance,
1234 uint8_t* data,
1235 size_t size)
1236 {
1237 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)->Serialize(data, size);
1238 }
1239
1240 inline static GAME_ERROR ADDON_Deserialize(const AddonInstance_Game* instance,
1241 const uint8_t* data,
1242 size_t size)
1243 {
1244 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)->Deserialize(data, size);
1245 }
1246
1247 // --- Cheat operations --------------------------------------------------------
1248
1249 inline static GAME_ERROR ADDON_CheatReset(const AddonInstance_Game* instance)
1250 {
1251 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)->CheatReset();
1252 }
1253
1254 inline static GAME_ERROR ADDON_GetMemory(const AddonInstance_Game* instance,
1255 GAME_MEMORY type,
1256 uint8_t** data,
1257 size_t* size)
1258 {
1259 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)
1260 ->GetMemory(type, *data, *size);
1261 }
1262
1263 inline static GAME_ERROR ADDON_SetCheat(const AddonInstance_Game* instance,
1264 unsigned int index,
1265 bool enabled,
1266 const char* code)
1267 {
1268 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)
1269 ->SetCheat(index, enabled, code);
1270 }
1271
1272 inline static GAME_ERROR ADDON_RCGenerateHashFromFile(const AddonInstance_Game* instance,
1273 char** hash,
1274 unsigned int consoleID,
1275 const char* filePath)
1276 {
1277 std::string cppHash;
1278
1279 GAME_ERROR ret = static_cast<CInstanceGame*>(instance->toAddon->addonInstance)
1280 ->RCGenerateHashFromFile(cppHash, consoleID, filePath);
1281 if (!cppHash.empty() && hash)
1282 {
1283 *hash = new char[cppHash.size() + 1];
1284 std::copy(cppHash.begin(), cppHash.end(), *hash);
1285 (*hash)[cppHash.size()] = '\0';
1286 }
1287 return ret;
1288 }
1289
1290 inline static GAME_ERROR ADDON_RCGetGameIDUrl(const AddonInstance_Game* instance,
1291 char** url,
1292 const char* hash)
1293 {
1294 std::string cppUrl;
1295 GAME_ERROR ret =
1296 static_cast<CInstanceGame*>(instance->toAddon->addonInstance)->RCGetGameIDUrl(cppUrl, hash);
1297 if (!cppUrl.empty() && url)
1298 {
1299 *url = new char[cppUrl.size() + 1];
1300 std::copy(cppUrl.begin(), cppUrl.end(), *url);
1301 (*url)[cppUrl.size()] = '\0';
1302 }
1303 return ret;
1304 }
1305
1306 inline static GAME_ERROR ADDON_RCGetPatchFileUrl(const AddonInstance_Game* instance,
1307 char** url,
1308 const char* username,
1309 const char* token,
1310 unsigned int gameID)
1311 {
1312 std::string cppUrl;
1313
1314 GAME_ERROR ret = static_cast<CInstanceGame*>(instance->toAddon->addonInstance)
1315 ->RCGetPatchFileUrl(cppUrl, username, token, gameID);
1316 if (!cppUrl.empty() && url)
1317 {
1318 *url = new char[cppUrl.size() + 1];
1319 std::copy(cppUrl.begin(), cppUrl.end(), *url);
1320 (*url)[cppUrl.size()] = '\0';
1321 }
1322 return ret;
1323 }
1324
1325 inline static GAME_ERROR ADDON_RCPostRichPresenceUrl(const AddonInstance_Game* instance,
1326 char** url,
1327 char** postData,
1328 const char* username,
1329 const char* token,
1330 unsigned int gameID,
1331 const char* richPresence)
1332 {
1333 std::string cppUrl;
1334 std::string cppPostData;
1335 GAME_ERROR ret =
1336 static_cast<CInstanceGame*>(instance->toAddon->addonInstance)
1337 ->RCPostRichPresenceUrl(cppUrl, cppPostData, username, token, gameID, richPresence);
1338 if (!cppUrl.empty())
1339 {
1340 *url = new char[cppUrl.size() + 1];
1341 std::copy(cppUrl.begin(), cppUrl.end(), *url);
1342 (*url)[cppUrl.size()] = '\0';
1343 }
1344 if (!cppPostData.empty())
1345 {
1346 *postData = new char[cppPostData.size() + 1];
1347 std::copy(cppPostData.begin(), cppPostData.end(), *postData);
1348 (*postData)[cppPostData.size()] = '\0';
1349 }
1350
1351 return ret;
1352 }
1353
1354 inline static GAME_ERROR ADDON_RCEnableRichPresence(const AddonInstance_Game* instance,
1355 const char* script)
1356 {
1357 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)
1358 ->RCEnableRichPresence(script);
1359 }
1360
1361 inline static GAME_ERROR ADDON_RCGetRichPresenceEvaluation(const AddonInstance_Game* instance,
1362 char** evaluation,
1363 unsigned int consoleID)
1364 {
1365 std::string cppEvaluation;
1366 GAME_ERROR ret = static_cast<CInstanceGame*>(instance->toAddon->addonInstance)
1367 ->RCGetRichPresenceEvaluation(cppEvaluation, consoleID);
1368 if (!cppEvaluation.empty())
1369 {
1370 *evaluation = new char[cppEvaluation.size() + 1];
1371 std::copy(cppEvaluation.begin(), cppEvaluation.end(), *evaluation);
1372 (*evaluation)[cppEvaluation.size()] = '\0';
1373 }
1374
1375 return ret;
1376 }
1377
1378 inline static GAME_ERROR ADDON_RCResetRuntime(const AddonInstance_Game* instance)
1379 {
1380 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)->RCResetRuntime();
1381 }
1382
1383 inline static void ADDON_FreeString(const AddonInstance_Game* instance, char* str)
1384 {
1385 delete[] str;
1386 }
1387
1388 AddonInstance_Game* m_instanceData;
1389};
1390
1391} /* namespace addon */
1392} /* namespace kodi */
1393
1394#endif /* __cplusplus */
Definition AddonBase.h:498
@ ADDON_LOG_INFO
1 : To include information messages in the log file.
Definition addon_base.h:187
CInstanceGame()
Game class constructor.
Definition Game.h:160
std::string GameClientDllPath() const
Callback to Kodi Function The path of the game client being loaded.
Definition Game.h:186
bool ProxyDllPaths(std::vector< std::string > &paths)
Callback to Kodi Function Paths to proxy DLLs used to load the game client.
Definition Game.h:199
bool ResourceDirectories(std::vector< std::string > &dirs)
Callback to Kodi Function The "system" directories of the frontend.
Definition Game.h:223
std::string ProfileDirectory() const
Callback to Kodi Function The writable directory of the frontend.
Definition Game.h:246
bool SupportsVFS() const
Callback to Kodi Function The value of the <supports_vfs> property from addon.xml.
Definition Game.h:257
~CInstanceGame() override=default
Destructor.
bool Extensions(std::vector< std::string > &extensions)
Callback to Kodi Function The extensions in the <extensions> property from addon.xml.
Definition Game.h:270
virtual GAME_ERROR RCGetRichPresenceEvaluation(std::string &evaluation, unsigned int consoleID)
Gets the rich presence evaluation for the current frame. Rich presence must be enabled first or this ...
Definition Game.h:1019
virtual GAME_ERROR RCGetPatchFileUrl(std::string &url, const std::string &username, const std::string &token, unsigned int gameID)
Gets a URL to the endpoint that returns the patch file.
Definition Game.h:960
virtual GAME_ERROR RCGenerateHashFromFile(std::string &hash, unsigned int consoleID, const std::string &filePath)
Generates a RetroAchievements hash for a given game that can be used to identify the game by RetroAch...
Definition Game.h:928
virtual GAME_ERROR RCPostRichPresenceUrl(std::string &url, std::string &postData, const std::string &username, const std::string &token, unsigned int gameID, const std::string &richPresence)
Gets a URL to the endpoint that updates the rich presence in the user's RetroAchievements profile.
Definition Game.h:984
virtual GAME_ERROR RCGetGameIDUrl(std::string &url, const std::string &hash)
Gets a URL to the endpoint that returns the game ID.
Definition Game.h:944
virtual GAME_ERROR RCEnableRichPresence(const std::string &script)
Enables rich presence.
Definition Game.h:1001
virtual GAME_ERROR RCResetRuntime()
Resets the runtime. Must be called each time a new rom is starting and when the savestate is changed.
Definition Game.h:1031
virtual GAME_ERROR CheatReset()
Reset the cheat system.
Definition Game.h:884
virtual GAME_ERROR GetMemory(GAME_MEMORY type, uint8_t *&data, size_t &size)
Get a region of memory.
Definition Game.h:896
virtual GAME_ERROR SetCheat(unsigned int index, bool enabled, const std::string &code)
Set a cheat code.
Definition Game.h:911
Game system timing.
Definition game.h:1134
GAME_REGION
Game region definition
Definition game.h:585
SPECIAL_GAME_TYPE
Special game types passed into game_load_game_special().
Definition game.h:603
GAME_MEMORY
Game Memory
Definition game.h:622
@ GAME_REGION_UNKNOWN
Game region unknown.
Definition game.h:587
void(* game_proc_address_t)(void)
Hardware framebuffer process function address
Definition game.h:425
Hardware rendering properties
Definition game.h:337
std::vector< std::string > analog_buttons
Analog buttons.
Definition Game.h:85
std::vector< std::string > accelerometers
Accelerometers.
Definition Game.h:91
bool provides_input
Provides input.
Definition Game.h:79
std::vector< std::string > digital_buttons
Digital buttons.
Definition Game.h:82
std::vector< std::string > abs_pointers
Absolute pointers.
Definition Game.h:100
std::vector< std::string > motors
Motors.
Definition Game.h:103
std::string controller_id
Controller identifier.
Definition Game.h:74
std::vector< std::string > rel_pointers
Relative pointers.
Definition Game.h:97
std::vector< std::string > keys
Keys.
Definition Game.h:94
std::vector< std::string > analog_sticks
Analog sticks.
Definition Game.h:88
"C" Game add-on controller layout.
Definition game.h:870
An input event.
Definition game.h:1073
The input topology is the possible ways to connect input devices.
Definition game.h:945
Stream buffers for hardware rendering and zero-copy support
Definition game.h:527
Stream packet and ephemeral metadata
Definition game.h:550
Immutable stream metadata
Definition game.h:502
GAME_ERROR
Game add-on error codes
Definition game.h:28
@ GAME_ERROR_NOT_IMPLEMENTED
The method called by the frontend is not implemented.
Definition game.h:36
virtual GAME_ERROR HwContextDestroy()
Called before the context is destroyed.
Definition Game.h:612
virtual GAME_ERROR HwContextReset()
Invalidates the current HW context and reinitializes GPU resources.
Definition Game.h:602
bool EnableHardwareRendering(const game_hw_rendering_properties &properties)
Callback to Kodi Function Enable hardware rendering functionality
Definition Game.h:588
game_proc_address_t HwGetProcAddress(const char *sym)
Callback to Kodi Function Get a symbol from the hardware context
Definition Game.h:623
virtual bool HasFeature(const std::string &controller_id, const std::string &feature_name)
Check if input is accepted for a feature on the controller.
Definition Game.h:661
virtual bool InputEvent(const game_input_event &event)
Notify the add-on of an input event.
Definition Game.h:784
virtual void FreeTopology(game_input_topology *topology)
Free the topology's resources.
Definition Game.h:686
virtual bool ConnectController(bool connect, const std::string &port_address, const std::string &controller_id)
Connect/disconnect a controller to a port on the virtual game console.
Definition Game.h:769
virtual void SetControllerLayouts(const std::vector< kodi::addon::GameControllerLayout > &controllers)
Set the layouts for known controllers.
Definition Game.h:697
virtual bool EnableMouse(bool enable, const std::string &controller_id)
Enable/disable mouse input using the specified controller.
Definition Game.h:722
virtual bool EnableKeyboard(bool enable, const std::string &controller_id)
Enable/disable keyboard input using the specified controller.
Definition Game.h:711
bool KodiInputEvent(const game_input_event &event)
Callback to Kodi Function Notify the port of an input event
Definition Game.h:799
virtual game_input_topology * GetTopology()
Get the input topology that specifies which controllers can be connected.
Definition Game.h:678
bool IsOpen() const
Check if the stream opened correctly, e.g. after calling the constructor.
Definition Game.h:551
void ReleaseBuffer(game_stream_buffer &buffer)
Free an allocated buffer.
Definition Game.h:531
void Close()
Free the specified stream.
Definition Game.h:464
bool GetBuffer(unsigned int width, unsigned int height, game_stream_buffer &buffer)
Get a buffer for zero-copy stream data.
Definition Game.h:491
void AddData(const game_stream_packet &packet)
Add a data packet to a stream.
Definition Game.h:511
bool Open(const game_stream_properties &properties)
Create a stream for gameplay data.
Definition Game.h:439
virtual GAME_ERROR LoadGameSpecial(SPECIAL_GAME_TYPE type, const std::vector< std::string > &urls)
Load a game that requires multiple files.
Definition Game.h:323
virtual GAME_ERROR UnloadGame()
Unload the current game.
Definition Game.h:349
virtual GAME_ERROR GetGameTiming(game_system_timing &timing_info)
Get timing information about the loaded game.
Definition Game.h:359
virtual GAME_ERROR RunFrame()
Run a single frame for add-ons that use a game loop.
Definition Game.h:389
virtual bool RequiresGameLoop()
Return true if the client requires the frontend to provide a game loop.
Definition Game.h:381
virtual GAME_ERROR Reset()
Reset the current game.
Definition Game.h:397
virtual GAME_ERROR LoadStandalone()
Begin playing without a game file.
Definition Game.h:339
void CloseGame(void)
Callback to Kodi Function Requests the frontend to stop the current game
Definition Game.h:406
virtual GAME_ERROR LoadGame(const std::string &url)
Load a game.
Definition Game.h:312
virtual GAME_REGION GetRegion()
Get region of the loaded game.
Definition Game.h:370
virtual GAME_ERROR Deserialize(const uint8_t *data, size_t size)
Deserialize the game from the given state.
Definition Game.h:852
virtual GAME_ERROR Serialize(uint8_t *data, size_t size)
Serialize the state of the game.
Definition Game.h:841
virtual size_t SerializeSize()
Get the number of bytes required to serialize the game.
Definition Game.h:830
void ATTR_DLL_LOCAL Log(const ADDON_LOG loglevel, const char *format,...)
Add a message to Kodi's log.
Definition AddonBase.h:1935
std::string ATTR_DLL_LOCAL GetRegion(const std::string &id)
Returns your regions setting as a string for the specified id.
Definition General.h:331
Game instance.
Definition game.h:1306
Game callbacks.
Definition game.h:1219
Definition addon_base.h:268
Internal used structure to have stored C API data above and available for everything below.
Definition AddonBase.h:73