Kodi Development 22.0
for Binary and Script based Add-Ons
 
Loading...
Searching...
No Matches
Game.h
1/*
2 * Copyright (C) 2014-2018 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 //============================================================================
162 CInstanceGame() : IAddonInstance(IInstanceInfo(CPrivateBase::m_interface->firstKodiInstance))
163 {
164 if (CPrivateBase::m_interface->globalSingleInstance != nullptr)
165 throw std::logic_error("kodi::addon::CInstanceGame: Creation of more as one in single "
166 "instance way is not allowed!");
167
168 SetAddonStruct(CPrivateBase::m_interface->firstKodiInstance);
169 CPrivateBase::m_interface->globalSingleInstance = this;
170 }
171 //----------------------------------------------------------------------------
172
173 //============================================================================
176 ~CInstanceGame() override = default;
177 //----------------------------------------------------------------------------
178
179 //============================================================================
187 std::string GameClientDllPath() const { return m_instanceData->props->game_client_dll_path; }
188 //----------------------------------------------------------------------------
189
190 //============================================================================
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 //============================================================================
221 bool ResourceDirectories(std::vector<std::string>& dirs)
222 {
223 for (unsigned int i = 0; i < m_instanceData->props->resource_directory_count; ++i)
224 {
225 if (m_instanceData->props->resource_directories[i] != nullptr)
226 dirs.emplace_back(m_instanceData->props->resource_directories[i]);
227 }
228 return !dirs.empty();
229 }
230 //----------------------------------------------------------------------------
231
232 //============================================================================
244 std::string ProfileDirectory() const { return m_instanceData->props->profile_directory; }
245 //----------------------------------------------------------------------------
246
247 //============================================================================
255 bool SupportsVFS() const { return m_instanceData->props->supports_vfs; }
256 //----------------------------------------------------------------------------
257
258 //============================================================================
267 bool Extensions(std::vector<std::string>& extensions)
268 {
269 for (unsigned int i = 0; i < m_instanceData->props->extension_count; ++i)
270 {
271 if (m_instanceData->props->extensions[i] != nullptr)
272 extensions.emplace_back(m_instanceData->props->extensions[i]);
273 }
274 return !extensions.empty();
275 }
276 //----------------------------------------------------------------------------
277
279
280 //--==----==----==----==----==----==----==----==----==----==----==----==----==--
281
282 //============================================================================
302
303 //============================================================================
309 virtual GAME_ERROR LoadGame(const std::string& url) { return GAME_ERROR_NOT_IMPLEMENTED; }
310 //----------------------------------------------------------------------------
311
312 //============================================================================
319 virtual GAME_ERROR LoadGameSpecial(SPECIAL_GAME_TYPE type, const std::vector<std::string>& urls)
320 {
322 }
323 //----------------------------------------------------------------------------
324
325 //============================================================================
336 //----------------------------------------------------------------------------
337
338 //============================================================================
346 //----------------------------------------------------------------------------
347
348 //============================================================================
356 {
358 }
359 //----------------------------------------------------------------------------
360
361 //============================================================================
367 //----------------------------------------------------------------------------
368
369 //============================================================================
377 virtual bool RequiresGameLoop() { return false; }
378 //----------------------------------------------------------------------------
379
380 //============================================================================
386 //----------------------------------------------------------------------------
387
388 //============================================================================
394 //----------------------------------------------------------------------------
395
396 //==========================================================================
402 void CloseGame(void) { m_instanceData->toKodi->CloseGame(m_instanceData->toKodi->kodiInstance); }
403 //----------------------------------------------------------------------------
404
405 //============================================================================
417 class CStream
418 {
419 public:
420 CStream() = default;
421
422 CStream(const game_stream_properties& properties) { Open(properties); }
423
424 ~CStream() { Close(); }
425
426 //==========================================================================
435 bool Open(const game_stream_properties& properties)
436 {
437 if (!CPrivateBase::m_interface->globalSingleInstance)
438 return false;
439
440 if (m_handle)
441 {
442 kodi::Log(ADDON_LOG_INFO, "kodi::addon::CInstanceGame::CStream already becomes reopened");
443 Close();
444 }
445
447 *static_cast<CInstanceGame*>(CPrivateBase::m_interface->globalSingleInstance)
448 ->m_instanceData->toKodi;
449 m_handle = cb.OpenStream(cb.kodiInstance, &properties);
450 return m_handle != nullptr;
451 }
452 //--------------------------------------------------------------------------
453
454 //==========================================================================
460 void Close()
461 {
462 if (!m_handle || !CPrivateBase::m_interface->globalSingleInstance)
463 return;
464
466 *static_cast<CInstanceGame*>(CPrivateBase::m_interface->globalSingleInstance)
467 ->m_instanceData->toKodi;
468 cb.CloseStream(cb.kodiInstance, m_handle);
469 m_handle = nullptr;
470 }
471 //--------------------------------------------------------------------------
472
473 //==========================================================================
486 bool GetBuffer(unsigned int width, unsigned int height, game_stream_buffer& buffer)
487 {
488 if (!m_handle || !CPrivateBase::m_interface->globalSingleInstance)
489 return false;
490
492 *static_cast<CInstanceGame*>(CPrivateBase::m_interface->globalSingleInstance)
493 ->m_instanceData->toKodi;
494 return cb.GetStreamBuffer(cb.kodiInstance, m_handle, width, height, &buffer);
495 }
496 //--------------------------------------------------------------------------
497
498 //==========================================================================
506 void AddData(const game_stream_packet& packet)
507 {
508 if (!m_handle || !CPrivateBase::m_interface->globalSingleInstance)
509 return;
510
512 *static_cast<CInstanceGame*>(CPrivateBase::m_interface->globalSingleInstance)
513 ->m_instanceData->toKodi;
514 cb.AddStreamData(cb.kodiInstance, m_handle, &packet);
515 }
516 //--------------------------------------------------------------------------
517
518 //==========================================================================
527 {
528 if (!m_handle || !CPrivateBase::m_interface->globalSingleInstance)
529 return;
530
532 *static_cast<CInstanceGame*>(CPrivateBase::m_interface->globalSingleInstance)
533 ->m_instanceData->toKodi;
534 cb.ReleaseStreamBuffer(cb.kodiInstance, m_handle, &buffer);
535 }
536 //--------------------------------------------------------------------------
537
538 //==========================================================================
546 bool IsOpen() const { return m_handle != nullptr; }
547 //--------------------------------------------------------------------------
548
549 private:
550 KODI_GAME_STREAM_HANDLE m_handle = nullptr;
551 };
552
553
555
556 //--==----==----==----==----==----==----==----==----==----==----==----==----==--
557
558 //============================================================================
575
576 //==========================================================================
585 {
586 return m_instanceData->toKodi->EnableHardwareRendering(m_instanceData->toKodi->kodiInstance,
587 &properties);
588 }
589 //----------------------------------------------------------------------------
590
591 //============================================================================
599 //----------------------------------------------------------------------------
600
601 //============================================================================
609
610 //============================================================================
620 {
621 return m_instanceData->toKodi->HwGetProcAddress(m_instanceData->toKodi->kodiInstance, sym);
622 }
623 //----------------------------------------------------------------------------
624
626
627 //--==----==----==----==----==----==----==----==----==----==----==----==----==--
628
629 //============================================================================
645
646 //============================================================================
658 virtual bool HasFeature(const std::string& controller_id, const std::string& feature_name)
659 {
660 return false;
661 }
662 //----------------------------------------------------------------------------
663
664 //============================================================================
675 virtual game_input_topology* GetTopology() { return nullptr; }
676 //----------------------------------------------------------------------------
677
678 //============================================================================
683 virtual void FreeTopology(game_input_topology* topology) {}
684 //----------------------------------------------------------------------------
685
686 //============================================================================
695 const std::vector<kodi::addon::GameControllerLayout>& controllers)
696 {
697 }
698 //----------------------------------------------------------------------------
699
700 //============================================================================
708 virtual bool EnableKeyboard(bool enable, const std::string& controller_id) { return false; }
709 //----------------------------------------------------------------------------
710
711 //============================================================================
719 virtual bool EnableMouse(bool enable, const std::string& controller_id) { return false; }
720 //--------------------------------------------------------------------------
721
722 //==========================================================================
765 virtual bool ConnectController(bool connect,
766 const std::string& port_address,
767 const std::string& controller_id)
768 {
769 return false;
770 }
771 //----------------------------------------------------------------------------
772
773 //============================================================================
780 virtual bool InputEvent(const game_input_event& event) { return false; }
781 //----------------------------------------------------------------------------
782
783 //============================================================================
795 {
796 return m_instanceData->toKodi->InputEvent(m_instanceData->toKodi->kodiInstance, &event);
797 }
798 //----------------------------------------------------------------------------
799
801
802 //--==----==----==----==----==----==----==----==----==----==----==----==----==--
803
804 //============================================================================
820
821 //============================================================================
826 virtual size_t SerializeSize() { return 0; }
827 //----------------------------------------------------------------------------
828
829 //============================================================================
837 virtual GAME_ERROR Serialize(uint8_t* data, size_t size) { return GAME_ERROR_NOT_IMPLEMENTED; }
838 //----------------------------------------------------------------------------
839
840 //============================================================================
848 virtual GAME_ERROR Deserialize(const uint8_t* data, size_t size)
849 {
851 }
852 //----------------------------------------------------------------------------
853
855
856 //--==----==----==----==----==----==----==----==----==----==----==----==----==--
857
858 //============================================================================
874
875 //============================================================================
881 //----------------------------------------------------------------------------
882
883 //============================================================================
892 virtual GAME_ERROR GetMemory(GAME_MEMORY type, uint8_t*& data, size_t& size)
893 {
895 }
896 //----------------------------------------------------------------------------
897
898 //============================================================================
907 virtual GAME_ERROR SetCheat(unsigned int index, bool enabled, const std::string& code)
908 {
910 }
911
912 //============================================================================
924 virtual GAME_ERROR RCGenerateHashFromFile(std::string& hash,
925 unsigned int consoleID,
926 const std::string& filePath)
927 {
929 }
930
931 //============================================================================
940 virtual GAME_ERROR RCGetGameIDUrl(std::string& url, const std::string& hash)
941 {
943 }
944
945 //============================================================================
956 virtual GAME_ERROR RCGetPatchFileUrl(std::string& url,
957 const std::string& username,
958 const std::string& token,
959 unsigned int gameID)
960 {
962 }
963
964 //============================================================================
980 virtual GAME_ERROR RCPostRichPresenceUrl(std::string& url,
981 std::string& postData,
982 const std::string& username,
983 const std::string& token,
984 unsigned int gameID,
985 const std::string& richPresence)
986 {
988 }
989
990 //============================================================================
997 virtual GAME_ERROR RCEnableRichPresence(const std::string& script)
998 {
1000 }
1001
1002 //============================================================================
1014 virtual GAME_ERROR RCGetRichPresenceEvaluation(std::string& evaluation, unsigned int consoleID)
1015 {
1017 }
1018
1019 //============================================================================
1027
1028 //----------------------------------------------------------------------------
1029
1031
1032private:
1033 void SetAddonStruct(KODI_ADDON_INSTANCE_STRUCT* instance)
1034 {
1035 instance->hdl = this;
1036
1037 instance->game->toAddon->LoadGame = ADDON_LoadGame;
1038 instance->game->toAddon->LoadGameSpecial = ADDON_LoadGameSpecial;
1039 instance->game->toAddon->LoadStandalone = ADDON_LoadStandalone;
1040 instance->game->toAddon->UnloadGame = ADDON_UnloadGame;
1041 instance->game->toAddon->GetGameTiming = ADDON_GetGameTiming;
1042 instance->game->toAddon->GetRegion = ADDON_GetRegion;
1043 instance->game->toAddon->RequiresGameLoop = ADDON_RequiresGameLoop;
1044 instance->game->toAddon->RunFrame = ADDON_RunFrame;
1045 instance->game->toAddon->Reset = ADDON_Reset;
1046
1047 instance->game->toAddon->HwContextReset = ADDON_HwContextReset;
1048 instance->game->toAddon->HwContextDestroy = ADDON_HwContextDestroy;
1049
1050 instance->game->toAddon->HasFeature = ADDON_HasFeature;
1051 instance->game->toAddon->GetTopology = ADDON_GetTopology;
1052 instance->game->toAddon->FreeTopology = ADDON_FreeTopology;
1053 instance->game->toAddon->SetControllerLayouts = ADDON_SetControllerLayouts;
1054 instance->game->toAddon->EnableKeyboard = ADDON_EnableKeyboard;
1055 instance->game->toAddon->EnableMouse = ADDON_EnableMouse;
1056 instance->game->toAddon->ConnectController = ADDON_ConnectController;
1057 instance->game->toAddon->InputEvent = ADDON_InputEvent;
1058
1059 instance->game->toAddon->SerializeSize = ADDON_SerializeSize;
1060 instance->game->toAddon->Serialize = ADDON_Serialize;
1061 instance->game->toAddon->Deserialize = ADDON_Deserialize;
1062
1063 instance->game->toAddon->CheatReset = ADDON_CheatReset;
1064 instance->game->toAddon->GetMemory = ADDON_GetMemory;
1065 instance->game->toAddon->SetCheat = ADDON_SetCheat;
1066
1067 instance->game->toAddon->RCGenerateHashFromFile = ADDON_RCGenerateHashFromFile;
1068 instance->game->toAddon->RCGetGameIDUrl = ADDON_RCGetGameIDUrl;
1069 instance->game->toAddon->RCGetPatchFileUrl = ADDON_RCGetPatchFileUrl;
1070 instance->game->toAddon->RCPostRichPresenceUrl = ADDON_RCPostRichPresenceUrl;
1071 instance->game->toAddon->RCEnableRichPresence = ADDON_RCEnableRichPresence;
1072 instance->game->toAddon->RCGetRichPresenceEvaluation = ADDON_RCGetRichPresenceEvaluation;
1073 instance->game->toAddon->RCResetRuntime = ADDON_RCResetRuntime;
1074
1075 instance->game->toAddon->FreeString = ADDON_FreeString;
1076
1077 m_instanceData = instance->game;
1078 m_instanceData->toAddon->addonInstance = this;
1079 }
1080
1081 // --- Game operations ---------------------------------------------------------
1082
1083 inline static GAME_ERROR ADDON_LoadGame(const AddonInstance_Game* instance, const char* url)
1084 {
1085 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)->LoadGame(url);
1086 }
1087
1088 inline static GAME_ERROR ADDON_LoadGameSpecial(const AddonInstance_Game* instance,
1089 SPECIAL_GAME_TYPE type,
1090 const char** urls,
1091 size_t urlCount)
1092 {
1093 std::vector<std::string> urlList;
1094 for (size_t i = 0; i < urlCount; ++i)
1095 {
1096 if (urls[i] != nullptr)
1097 urlList.emplace_back(urls[i]);
1098 }
1099
1100 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)
1101 ->LoadGameSpecial(type, urlList);
1102 }
1103
1104 inline static GAME_ERROR ADDON_LoadStandalone(const AddonInstance_Game* instance)
1105 {
1106 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)->LoadStandalone();
1107 }
1108
1109 inline static GAME_ERROR ADDON_UnloadGame(const AddonInstance_Game* instance)
1110 {
1111 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)->UnloadGame();
1112 }
1113
1114 inline static GAME_ERROR ADDON_GetGameTiming(const AddonInstance_Game* instance,
1115 game_system_timing* timing_info)
1116 {
1117 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)
1118 ->GetGameTiming(*timing_info);
1119 }
1120
1121 inline static GAME_REGION ADDON_GetRegion(const AddonInstance_Game* instance)
1122 {
1123 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)->GetRegion();
1124 }
1125
1126 inline static bool ADDON_RequiresGameLoop(const AddonInstance_Game* instance)
1127 {
1128 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)->RequiresGameLoop();
1129 }
1130
1131 inline static GAME_ERROR ADDON_RunFrame(const AddonInstance_Game* instance)
1132 {
1133 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)->RunFrame();
1134 }
1135
1136 inline static GAME_ERROR ADDON_Reset(const AddonInstance_Game* instance)
1137 {
1138 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)->Reset();
1139 }
1140
1141 // --- Hardware rendering operations -------------------------------------------
1142
1143 inline static GAME_ERROR ADDON_HwContextReset(const AddonInstance_Game* instance)
1144 {
1145 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)->HwContextReset();
1146 }
1147
1148 inline static GAME_ERROR ADDON_HwContextDestroy(const AddonInstance_Game* instance)
1149 {
1150 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)->HwContextDestroy();
1151 }
1152
1153 // --- Input operations --------------------------------------------------------
1154
1155 inline static bool ADDON_HasFeature(const AddonInstance_Game* instance,
1156 const char* controller_id,
1157 const char* feature_name)
1158 {
1159 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)
1160 ->HasFeature(controller_id, feature_name);
1161 }
1162
1163 inline static game_input_topology* ADDON_GetTopology(const AddonInstance_Game* instance)
1164 {
1165 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)->GetTopology();
1166 }
1167
1168 inline static void ADDON_FreeTopology(const AddonInstance_Game* instance,
1169 game_input_topology* topology)
1170 {
1171 static_cast<CInstanceGame*>(instance->toAddon->addonInstance)->FreeTopology(topology);
1172 }
1173
1174 inline static void ADDON_SetControllerLayouts(const AddonInstance_Game* instance,
1175 const game_controller_layout* controllers,
1176 unsigned int controller_count)
1177 {
1178 if (controllers == nullptr)
1179 return;
1180
1181 std::vector<GameControllerLayout> controllerList;
1182 for (unsigned int i = 0; i < controller_count; ++i)
1183 controllerList.emplace_back(controllers[i]);
1184
1185 static_cast<CInstanceGame*>(instance->toAddon->addonInstance)
1186 ->SetControllerLayouts(controllerList);
1187 }
1188
1189 inline static bool ADDON_EnableKeyboard(const AddonInstance_Game* instance,
1190 bool enable,
1191 const char* controller_id)
1192 {
1193 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)
1194 ->EnableKeyboard(enable, controller_id);
1195 }
1196
1197 inline static bool ADDON_EnableMouse(const AddonInstance_Game* instance,
1198 bool enable,
1199 const char* controller_id)
1200 {
1201 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)
1202 ->EnableMouse(enable, controller_id);
1203 }
1204
1205 inline static bool ADDON_ConnectController(const AddonInstance_Game* instance,
1206 bool connect,
1207 const char* port_address,
1208 const char* controller_id)
1209 {
1210 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)
1211 ->ConnectController(connect, port_address, controller_id);
1212 }
1213
1214 inline static bool ADDON_InputEvent(const AddonInstance_Game* instance,
1215 const game_input_event* event)
1216 {
1217 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)->InputEvent(*event);
1218 }
1219
1220 // --- Serialization operations ------------------------------------------------
1221
1222 inline static size_t ADDON_SerializeSize(const AddonInstance_Game* instance)
1223 {
1224 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)->SerializeSize();
1225 }
1226
1227 inline static GAME_ERROR ADDON_Serialize(const AddonInstance_Game* instance,
1228 uint8_t* data,
1229 size_t size)
1230 {
1231 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)->Serialize(data, size);
1232 }
1233
1234 inline static GAME_ERROR ADDON_Deserialize(const AddonInstance_Game* instance,
1235 const uint8_t* data,
1236 size_t size)
1237 {
1238 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)->Deserialize(data, size);
1239 }
1240
1241 // --- Cheat operations --------------------------------------------------------
1242
1243 inline static GAME_ERROR ADDON_CheatReset(const AddonInstance_Game* instance)
1244 {
1245 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)->CheatReset();
1246 }
1247
1248 inline static GAME_ERROR ADDON_GetMemory(const AddonInstance_Game* instance,
1249 GAME_MEMORY type,
1250 uint8_t** data,
1251 size_t* size)
1252 {
1253 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)
1254 ->GetMemory(type, *data, *size);
1255 }
1256
1257 inline static GAME_ERROR ADDON_SetCheat(const AddonInstance_Game* instance,
1258 unsigned int index,
1259 bool enabled,
1260 const char* code)
1261 {
1262 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)
1263 ->SetCheat(index, enabled, code);
1264 }
1265
1266 inline static GAME_ERROR ADDON_RCGenerateHashFromFile(const AddonInstance_Game* instance,
1267 char** hash,
1268 unsigned int consoleID,
1269 const char* filePath)
1270 {
1271 std::string cppHash;
1272
1273 GAME_ERROR ret = static_cast<CInstanceGame*>(instance->toAddon->addonInstance)
1274 ->RCGenerateHashFromFile(cppHash, consoleID, filePath);
1275 if (!cppHash.empty() && hash)
1276 {
1277 *hash = new char[cppHash.size() + 1];
1278 std::copy(cppHash.begin(), cppHash.end(), *hash);
1279 (*hash)[cppHash.size()] = '\0';
1280 }
1281 return ret;
1282 }
1283
1284 inline static GAME_ERROR ADDON_RCGetGameIDUrl(const AddonInstance_Game* instance,
1285 char** url,
1286 const char* hash)
1287 {
1288 std::string cppUrl;
1289 GAME_ERROR ret =
1290 static_cast<CInstanceGame*>(instance->toAddon->addonInstance)->RCGetGameIDUrl(cppUrl, hash);
1291 if (!cppUrl.empty() && url)
1292 {
1293 *url = new char[cppUrl.size() + 1];
1294 std::copy(cppUrl.begin(), cppUrl.end(), *url);
1295 (*url)[cppUrl.size()] = '\0';
1296 }
1297 return ret;
1298 }
1299
1300 inline static GAME_ERROR ADDON_RCGetPatchFileUrl(const AddonInstance_Game* instance,
1301 char** url,
1302 const char* username,
1303 const char* token,
1304 unsigned int gameID)
1305 {
1306 std::string cppUrl;
1307
1308 GAME_ERROR ret = static_cast<CInstanceGame*>(instance->toAddon->addonInstance)
1309 ->RCGetPatchFileUrl(cppUrl, username, token, gameID);
1310 if (!cppUrl.empty() && url)
1311 {
1312 *url = new char[cppUrl.size() + 1];
1313 std::copy(cppUrl.begin(), cppUrl.end(), *url);
1314 (*url)[cppUrl.size()] = '\0';
1315 }
1316 return ret;
1317 }
1318
1319 inline static GAME_ERROR ADDON_RCPostRichPresenceUrl(const AddonInstance_Game* instance,
1320 char** url,
1321 char** postData,
1322 const char* username,
1323 const char* token,
1324 unsigned int gameID,
1325 const char* richPresence)
1326 {
1327 std::string cppUrl;
1328 std::string cppPostData;
1329 GAME_ERROR ret =
1330 static_cast<CInstanceGame*>(instance->toAddon->addonInstance)
1331 ->RCPostRichPresenceUrl(cppUrl, cppPostData, username, token, gameID, richPresence);
1332 if (!cppUrl.empty())
1333 {
1334 *url = new char[cppUrl.size() + 1];
1335 std::copy(cppUrl.begin(), cppUrl.end(), *url);
1336 (*url)[cppUrl.size()] = '\0';
1337 }
1338 if (!cppPostData.empty())
1339 {
1340 *postData = new char[cppPostData.size() + 1];
1341 std::copy(cppPostData.begin(), cppPostData.end(), *postData);
1342 (*postData)[cppPostData.size()] = '\0';
1343 }
1344
1345 return ret;
1346 }
1347
1348 inline static GAME_ERROR ADDON_RCEnableRichPresence(const AddonInstance_Game* instance,
1349 const char* script)
1350 {
1351 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)
1352 ->RCEnableRichPresence(script);
1353 }
1354
1355 inline static GAME_ERROR ADDON_RCGetRichPresenceEvaluation(const AddonInstance_Game* instance,
1356 char** evaluation,
1357 unsigned int consoleID)
1358 {
1359 std::string cppEvaluation;
1360 GAME_ERROR ret = static_cast<CInstanceGame*>(instance->toAddon->addonInstance)
1361 ->RCGetRichPresenceEvaluation(cppEvaluation, consoleID);
1362 if (!cppEvaluation.empty())
1363 {
1364 *evaluation = new char[cppEvaluation.size() + 1];
1365 std::copy(cppEvaluation.begin(), cppEvaluation.end(), *evaluation);
1366 (*evaluation)[cppEvaluation.size()] = '\0';
1367 }
1368
1369 return ret;
1370 }
1371
1372 inline static GAME_ERROR ADDON_RCResetRuntime(const AddonInstance_Game* instance)
1373 {
1374 return static_cast<CInstanceGame*>(instance->toAddon->addonInstance)->RCResetRuntime();
1375 }
1376
1377 inline static void ADDON_FreeString(const AddonInstance_Game* instance, char* str)
1378 {
1379 delete[] str;
1380 }
1381
1382 AddonInstance_Game* m_instanceData;
1383};
1384
1385} /* namespace addon */
1386} /* namespace kodi */
1387
1388#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:162
std::string GameClientDllPath() const
Callback to Kodi Function The path of the game client being loaded.
Definition Game.h:187
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:221
std::string ProfileDirectory() const
Callback to Kodi Function The writable directory of the frontend.
Definition Game.h:244
bool SupportsVFS() const
Callback to Kodi Function The value of the <supports_vfs> property from addon.xml.
Definition Game.h:255
~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:267
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:1014
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:956
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:924
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:980
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:940
virtual GAME_ERROR RCEnableRichPresence(const std::string &script)
Enables rich presence.
Definition Game.h:997
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:1026
virtual GAME_ERROR CheatReset()
Reset the cheat system.
Definition Game.h:880
virtual GAME_ERROR GetMemory(GAME_MEMORY type, uint8_t *&data, size_t &size)
Get a region of memory.
Definition Game.h:892
virtual GAME_ERROR SetCheat(unsigned int index, bool enabled, const std::string &code)
Set a cheat code.
Definition Game.h:907
Game system timing.
Definition game.h:1125
GAME_REGION
Game region definition
Definition game.h:577
SPECIAL_GAME_TYPE
Special game types passed into game_load_game_special().
Definition game.h:595
GAME_MEMORY
Game Memory
Definition game.h:614
@ GAME_REGION_UNKNOWN
Game region unknown.
Definition game.h:579
void(* game_proc_address_t)(void)
Hardware framebuffer process function address
Definition game.h:417
Hardware rendering properties
Definition game.h:329
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:862
An input event.
Definition game.h:1064
The input topology is the possible ways to connect input devices.
Definition game.h:937
Stream buffers for hardware rendering and zero-copy support
Definition game.h:519
Stream packet and ephemeral metadata
Definition game.h:542
Immutable stream metadata
Definition game.h:494
GAME_ERROR
Game add-on error codes
Definition game.h:28
@ GAME_ERROR_NOT_IMPLEMENTED
the method that the frontend called is not implemented
Definition game.h:36
virtual GAME_ERROR HwContextDestroy()
Called before the context is destroyed.
Definition Game.h:608
virtual GAME_ERROR HwContextReset()
Invalidates the current HW context and reinitializes GPU resources.
Definition Game.h:598
bool EnableHardwareRendering(const game_hw_rendering_properties &properties)
Callback to Kodi Function Enable hardware rendering functionality
Definition Game.h:584
game_proc_address_t HwGetProcAddress(const char *sym)
Callback to Kodi Function Get a symbol from the hardware context
Definition Game.h:619
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:658
virtual bool InputEvent(const game_input_event &event)
Notify the add-on of an input event.
Definition Game.h:780
virtual void FreeTopology(game_input_topology *topology)
Free the topology's resources.
Definition Game.h:683
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:765
virtual void SetControllerLayouts(const std::vector< kodi::addon::GameControllerLayout > &controllers)
Set the layouts for known controllers.
Definition Game.h:694
virtual bool EnableMouse(bool enable, const std::string &controller_id)
Enable/disable mouse input using the specified controller.
Definition Game.h:719
virtual bool EnableKeyboard(bool enable, const std::string &controller_id)
Enable/disable keyboard input using the specified controller.
Definition Game.h:708
bool KodiInputEvent(const game_input_event &event)
Callback to Kodi Function Notify the port of an input event
Definition Game.h:794
virtual game_input_topology * GetTopology()
Get the input topology that specifies which controllers can be connected.
Definition Game.h:675
bool IsOpen() const
To check stream open was OK, e.g. after use of constructor.
Definition Game.h:546
void ReleaseBuffer(game_stream_buffer &buffer)
Free an allocated buffer.
Definition Game.h:526
void Close()
Free the specified stream.
Definition Game.h:460
bool GetBuffer(unsigned int width, unsigned int height, game_stream_buffer &buffer)
Get a buffer for zero-copy stream data.
Definition Game.h:486
void AddData(const game_stream_packet &packet)
Add a data packet to a stream.
Definition Game.h:506
bool Open(const game_stream_properties &properties)
Create a stream for gameplay data.
Definition Game.h:435
virtual GAME_ERROR LoadGameSpecial(SPECIAL_GAME_TYPE type, const std::vector< std::string > &urls)
Load a game that requires multiple files.
Definition Game.h:319
virtual GAME_ERROR UnloadGame()
Unload the current game.
Definition Game.h:345
virtual GAME_ERROR GetGameTiming(game_system_timing &timing_info)
Get timing information about the loaded game.
Definition Game.h:355
virtual GAME_ERROR RunFrame()
Run a single frame for add-ons that use a game loop.
Definition Game.h:385
virtual bool RequiresGameLoop()
Return true if the client requires the frontend to provide a game loop.
Definition Game.h:377
virtual GAME_ERROR Reset()
Reset the current game.
Definition Game.h:393
virtual GAME_ERROR LoadStandalone()
Begin playing without a game file.
Definition Game.h:335
void CloseGame(void)
Callback to Kodi Function Requests the frontend to stop the current game
Definition Game.h:402
virtual GAME_ERROR LoadGame(const std::string &url)
Load a game.
Definition Game.h:309
virtual GAME_REGION GetRegion()
Get region of the loaded game.
Definition Game.h:366
virtual GAME_ERROR Deserialize(const uint8_t *data, size_t size)
Deserialize the game from the given state.
Definition Game.h:848
virtual GAME_ERROR Serialize(uint8_t *data, size_t size)
Serialize the state of the game.
Definition Game.h:837
virtual size_t SerializeSize()
Get the number of bytes required to serialize the game.
Definition Game.h:826
void ATTR_DLL_LOCAL Log(const ADDON_LOG loglevel, const char *format,...)
Add a message to Kodi's log.
Definition AddonBase.h:1938
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:1297
Game callbacks.
Definition game.h:1210
Definition addon_base.h:268
Internal used structure to have stored C API data above and available for everything below.
Definition AddonBase.h:73