summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/Game.h
blob: a53f1e72b09135c72d9e9154b9dfac6b5c2a3042 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
/*
 *  Copyright (C) 2014-2018 Team Kodi
 *  This file is part of Kodi - https://kodi.tv
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#pragma once

#include "../AddonBase.h"

#ifdef BUILD_KODI_ADDON
#include "XBMC_vkeys.h"
#else
#include "input/XBMC_vkeys.h"
#endif

//==============================================================================
/// @addtogroup cpp_kodi_addon_game
///
/// To use on Libretro and for stand-alone games or emulators that does not use
/// the Libretro API.
///
/// Possible examples could be, Nvidia GameStream via Limelight or WINE capture
/// could possible through the Game API.
///

namespace kodi
{
namespace addon
{
class CInstanceGame;
}
} // namespace kodi

extern "C"
{

//==============================================================================
/// \defgroup cpp_kodi_addon_game_Defs Definitions, structures and enumerators
/// \ingroup cpp_kodi_addon_game
/// @brief **Game add-on instance definition values**
//------------------------------------------------------------------------------

//==============================================================================
/// \ingroup cpp_kodi_addon_game_Defs
/// @brief **Port ID used when topology is unknown**
#define DEFAULT_PORT_ID "1"
//------------------------------------------------------------------------------

//==============================================================================
/// \ingroup cpp_kodi_addon_game_Defs
/// @brief **Game add-on error codes**
///
/// Used as return values on most Game related functions.
///
typedef enum GAME_ERROR
{
  /// @brief no error occurred
  GAME_ERROR_NO_ERROR,

  /// @brief an unknown error occurred
  GAME_ERROR_UNKNOWN,

  /// @brief the method that the frontend called is not implemented
  GAME_ERROR_NOT_IMPLEMENTED,

  /// @brief the command was rejected by the game client
  GAME_ERROR_REJECTED,

  /// @brief the parameters of the method that was called are invalid for this operation
  GAME_ERROR_INVALID_PARAMETERS,

  /// @brief the command failed
  GAME_ERROR_FAILED,

  /// @brief no game is loaded
  GAME_ERROR_NOT_LOADED,

  /// @brief game requires restricted resources
  GAME_ERROR_RESTRICTED,
} GAME_ERROR;
//------------------------------------------------------------------------------

//--==----==----==----==----==----==----==----==----==----==----==----==----==--
/// \defgroup cpp_kodi_addon_game_Defs_AudioStream 1. Audio stream
/// \ingroup cpp_kodi_addon_game_Defs
/// @brief **The for Audio stream used data system**
///
/// Used to give Addon currently used audio stream configuration on Kodi and
/// arrays to give related data to Kodi on callbacks.
///
//@{

//==============================================================================
/// @brief **Stream Format**
///
/// From Kodi requested specified audio sample format.
///
typedef enum GAME_PCM_FORMAT
{
  GAME_PCM_FORMAT_UNKNOWN,

  /// @brief S16NE sample format
  GAME_PCM_FORMAT_S16NE,
} GAME_PCM_FORMAT;
//------------------------------------------------------------------------------

//==============================================================================
/// @brief **Audio channel**
///
/// Channel identification flags.
///
typedef enum GAME_AUDIO_CHANNEL
{
  /// @brief Channel list terminator
  GAME_CH_NULL,

  /// @brief Channel front left
  GAME_CH_FL,

  /// @brief Channel front right
  GAME_CH_FR,

  /// @brief Channel front center
  GAME_CH_FC,

  /// @brief Channel Low Frequency Effects / Subwoofer
  GAME_CH_LFE,

  /// @brief Channel back left
  GAME_CH_BL,

  /// @brief Channel back right
  GAME_CH_BR,

  /// @brief Channel front left over center
  GAME_CH_FLOC,

  /// @brief Channel front right over center
  GAME_CH_FROC,

  /// @brief Channel back center
  GAME_CH_BC,

  /// @brief Channel surround/side left
  GAME_CH_SL,

  /// @brief Channel surround/side right
  GAME_CH_SR,

  /// @brief Channel top front left
  GAME_CH_TFL,

  /// @brief Channel top front right
  GAME_CH_TFR,

  /// @brief Channel top front center
  GAME_CH_TFC,

  /// @brief Channel top center
  GAME_CH_TC,

  /// @brief Channel top back left
  GAME_CH_TBL,

  /// @brief Channel top back right
  GAME_CH_TBR,

  /// @brief Channel top back center
  GAME_CH_TBC,

  /// @brief Channel bacl left over center
  GAME_CH_BLOC,

  /// @brief Channel back right over center
  GAME_CH_BROC,
} GAME_AUDIO_CHANNEL;
//------------------------------------------------------------------------------

//==============================================================================
/// @brief **Game audio stream properties**
///
/// Used by Kodi to pass the currently required audio stream settings to the addon
///
typedef struct game_stream_audio_properties
{
  GAME_PCM_FORMAT format;
  const GAME_AUDIO_CHANNEL* channel_map;
} ATTRIBUTE_PACKED game_stream_audio_properties;
//------------------------------------------------------------------------------

//==============================================================================
/// @brief **Audio stream packet**
///
/// This packet contains audio stream data passed to Kodi.
///
typedef struct game_stream_audio_packet
{
  /// @brief Pointer for audio stream data given to Kodi
  const uint8_t *data;

  /// @brief Size of data array
  size_t size;
} ATTRIBUTE_PACKED game_stream_audio_packet;
//------------------------------------------------------------------------------

//@}

//--==----==----==----==----==----==----==----==----==----==----==----==----==--
/// \defgroup cpp_kodi_addon_game_Defs_VideoStream 2. Video stream
/// \ingroup cpp_kodi_addon_game_Defs
/// @brief **The for Video stream used data system**
///
/// Used to give Addon currently used video stream configuration on Kodi and
/// arrays to give related data to Kodi on callbacks.
///
//@{

//==============================================================================
/// @brief **Pixel format**
///
/// From Kodi requested specified video RGB color model format.
///
typedef enum GAME_PIXEL_FORMAT
{
  GAME_PIXEL_FORMAT_UNKNOWN,

  /// @brief 0RGB8888 Format
  GAME_PIXEL_FORMAT_0RGB8888,

  /// @brief RGB565 Format
  GAME_PIXEL_FORMAT_RGB565,

  /// @brief 0RGB1555 Format
  GAME_PIXEL_FORMAT_0RGB1555,
} GAME_PIXEL_FORMAT;
//------------------------------------------------------------------------------

//==============================================================================
/// @brief **Video rotation position**
///
/// To define position how video becomes shown.
///
typedef enum GAME_VIDEO_ROTATION
{
  /// @brief 0° and Without rotation
  GAME_VIDEO_ROTATION_0,

  /// @brief rotate 90° counterclockwise
  GAME_VIDEO_ROTATION_90_CCW,

  /// @brief rotate 180° counterclockwise
  GAME_VIDEO_ROTATION_180_CCW,

  /// @brief rotate 270° counterclockwise
  GAME_VIDEO_ROTATION_270_CCW,
} GAME_VIDEO_ROTATION;
//------------------------------------------------------------------------------

//==============================================================================
/// @brief **Game video stream properties**
///
/// Used by Kodi to pass the currently required video stream settings to the addon
///
typedef struct game_stream_video_properties
{
  /// @brief The to used pixel format
  GAME_PIXEL_FORMAT format;

  /// @brief The nominal used width
  unsigned int nominal_width;

  /// @brief The nominal used height
  unsigned int nominal_height;

  /// @brief The maximal used width
  unsigned int max_width;

  /// @brief The maximal used height
  unsigned int max_height;

  /// @brief On video stream used aspect ration
  ///
  /// @note If aspect_ratio is <= 0.0, an aspect ratio of nominal_width / nominal_height is assumed
  float aspect_ratio;
} ATTRIBUTE_PACKED game_stream_video_properties;
//------------------------------------------------------------------------------

//==============================================================================
/// @brief **Video stream packet**
///
/// This packet contains video stream data passed to Kodi.
///
typedef struct game_stream_video_packet
{
  /// @brief Video height
  unsigned int width;

  /// @brief Video width
  unsigned int height;

  /// @brief Width @ref GAME_VIDEO_ROTATION defined rotation angle.
  GAME_VIDEO_ROTATION rotation;

  /// @brief Pointer for video stream data given to Kodi
  const uint8_t *data;

  /// @brief Size of data array
  size_t size;
} ATTRIBUTE_PACKED game_stream_video_packet;
//------------------------------------------------------------------------------

//@}

//--==----==----==----==----==----==----==----==----==----==----==----==----==--
/// \defgroup cpp_kodi_addon_game_Defs_HardwareFramebuffer 3. Hardware framebuffer stream
/// \ingroup cpp_kodi_addon_game_Defs
/// @brief **Hardware framebuffer stream data**
///
//@{

//==============================================================================
/// @brief **Hardware framebuffer type**
///
typedef enum GAME_HW_CONTEXT_TYPE
{
  /// @brief None context
  GAME_HW_CONTEXT_NONE,

  /// @brief OpenGL 2.x. Driver can choose to use latest compatibility context
  GAME_HW_CONTEXT_OPENGL,

  /// @brief OpenGL ES 2.0
  GAME_HW_CONTEXT_OPENGLES2,

  /// @brief Modern desktop core GL context. Use major/minor fields to set GL version
  GAME_HW_CONTEXT_OPENGL_CORE,

  /// @brief OpenGL ES 3.0
  GAME_HW_CONTEXT_OPENGLES3,

  /// @brief OpenGL ES 3.1+. Set major/minor fields.
  GAME_HW_CONTEXT_OPENGLES_VERSION,

  /// @brief Vulkan
  GAME_HW_CONTEXT_VULKAN
} GAME_HW_CONTEXT_TYPE;
//------------------------------------------------------------------------------

//==============================================================================
/// @brief **Hardware framebuffer properties**
///
typedef struct game_stream_hw_framebuffer_properties
{
  /// @brief The API to use.
  ///
  GAME_HW_CONTEXT_TYPE context_type;

  /// @brief Set if render buffers should have depth component attached.
  ///
  /// @todo: Obsolete
  ///
  bool depth;

  /// @brief Set if stencil buffers should be attached.
  ///
  /// If depth and stencil are true, a packed 24/8 buffer will be added.
  /// Only attaching stencil is invalid and will be ignored.
  ///
  /// @todo: Obsolete.
  ///
  bool stencil;

  /// @brief Use conventional bottom-left origin convention.
  ///
  /// If false, standard top-left origin semantics are used.
  ///
  /// @todo: Move to GL specific interface
  ///
  bool bottom_left_origin;

  /// @brief Major version number for core GL context or GLES 3.1+.
  unsigned int version_major;

  /// @brief Minor version number for core GL context or GLES 3.1+.
  unsigned int version_minor;

  /// @brief If this is true, the frontend will go very far to avoid resetting context
  /// in scenarios like toggling fullscreen, etc.
  ///
  /// @todo: Obsolete? Maybe frontend should just always assume this...
  ///
  /// The reset callback might still be called in extreme situations such as if
  /// the context is lost beyond recovery.
  ///
  /// For optimal stability, set this to false, and allow context to be reset at
  /// any time.
  ///
  bool cache_context;

  /// @brief Creates a debug context.
  bool debug_context;
} ATTRIBUTE_PACKED game_stream_hw_framebuffer_properties;
//------------------------------------------------------------------------------

//==============================================================================
/// @brief **Hardware framebuffer buffer**
///
typedef struct game_stream_hw_framebuffer_buffer
{
  /// @brief
  uintptr_t framebuffer;
} ATTRIBUTE_PACKED game_stream_hw_framebuffer_buffer;
//------------------------------------------------------------------------------

//==============================================================================
/// @brief **Hardware framebuffer packet**
///
typedef struct game_stream_hw_framebuffer_packet
{
  /// @brief
  uintptr_t framebuffer;
} ATTRIBUTE_PACKED game_stream_hw_framebuffer_packet;
//------------------------------------------------------------------------------

//==============================================================================
/// @brief **Hardware framebuffer process function address**
///
typedef void (*game_proc_address_t)(void);
//------------------------------------------------------------------------------

//@}

//--==----==----==----==----==----==----==----==----==----==----==----==----==--
/// \defgroup cpp_kodi_addon_game_Defs_SoftwareFramebuffer 4. Software framebuffer stream
/// \ingroup cpp_kodi_addon_game_Defs
/// @brief **Software framebuffer stream data**
///
//@{

//==============================================================================
/// @brief **Game video stream properties**
///
/// Used by Kodi to pass the currently required video stream settings to the addon
///
typedef game_stream_video_properties game_stream_sw_framebuffer_properties;
//------------------------------------------------------------------------------

//==============================================================================
/// @brief **Hardware framebuffer type**
///
typedef struct game_stream_sw_framebuffer_buffer
{
  GAME_PIXEL_FORMAT format;
  uint8_t *data;
  size_t size;
} ATTRIBUTE_PACKED game_stream_sw_framebuffer_buffer;
//------------------------------------------------------------------------------

//==============================================================================
/// @brief **Video stream packet**
///
/// This packet contains video stream data passed to Kodi.
///
typedef game_stream_video_packet game_stream_sw_framebuffer_packet;
//------------------------------------------------------------------------------

//@}

//--==----==----==----==----==----==----==----==----==----==----==----==----==--
/// \defgroup cpp_kodi_addon_game_Defs_StreamTypes 5. Stream types
/// \ingroup cpp_kodi_addon_game_Defs
/// @brief **Stream types data**
///
//@{

//==============================================================================
/// @brief **Game stream types**
///
typedef enum GAME_STREAM_TYPE
{
  /// @brief Unknown
  GAME_STREAM_UNKNOWN,

  /// @brief Audio stream
  GAME_STREAM_AUDIO,

  /// @brief Video stream
  GAME_STREAM_VIDEO,

  /// @brief Hardware framebuffer
  GAME_STREAM_HW_FRAMEBUFFER,

  /// @brief Software framebuffer
  GAME_STREAM_SW_FRAMEBUFFER,
} GAME_STREAM_TYPE;
//------------------------------------------------------------------------------

//==============================================================================
/// @brief **Immutable stream metadata**
///
/// This metadata is provided when the stream is opened. If any stream
/// properties change, a new stream must be opened.
///
typedef struct game_stream_properties
{
  /// @brief
  GAME_STREAM_TYPE type;
  union
  {
    /// @brief
    game_stream_audio_properties audio;

    /// @brief
    game_stream_video_properties video;

    /// @brief
    game_stream_hw_framebuffer_properties hw_framebuffer;

    /// @brief
    game_stream_sw_framebuffer_properties sw_framebuffer;
  };
} ATTRIBUTE_PACKED game_stream_properties;
//------------------------------------------------------------------------------

//==============================================================================
/// @brief **Stream buffers for hardware rendering and zero-copy support**
///
typedef struct game_stream_buffer
{
  /// @brief
  GAME_STREAM_TYPE type;
  union
  {
    /// @brief
    game_stream_hw_framebuffer_buffer hw_framebuffer;

    /// @brief
    game_stream_sw_framebuffer_buffer sw_framebuffer;
  };
} ATTRIBUTE_PACKED game_stream_buffer;
//------------------------------------------------------------------------------

//==============================================================================
/// @brief **Stream packet and ephemeral metadata**
///
/// This packet contains stream data and accompanying metadata. The metadata
/// is ephemeral, meaning it only applies to the current packet and can change
/// from packet to packet in the same stream.
///
typedef struct game_stream_packet
{
  /// @brief
  GAME_STREAM_TYPE type;
  union
  {
    /// @brief
    game_stream_audio_packet audio;

    /// @brief
    game_stream_video_packet video;

    /// @brief
    game_stream_hw_framebuffer_packet hw_framebuffer;

    /// @brief
    game_stream_sw_framebuffer_packet sw_framebuffer;
  };
} ATTRIBUTE_PACKED game_stream_packet;
//------------------------------------------------------------------------------

//@}

//--==----==----==----==----==----==----==----==----==----==----==----==----==--
/// \defgroup cpp_kodi_addon_game_Defs_GameTypes 6. Game types
/// \ingroup cpp_kodi_addon_game_Defs
/// @brief **Game types data**
///
//@{

//==============================================================================
/// @brief **Game reguin definition**
///
/// Returned from game_get_region()
typedef enum GAME_REGION
{
  /// @brief Game region unknown
  GAME_REGION_UNKNOWN,

  /// @brief Game region NTSC
  GAME_REGION_NTSC,

  /// @brief Game region PAL
  GAME_REGION_PAL,
} GAME_REGION;
//------------------------------------------------------------------------------

//==============================================================================
/// @brief **Special game types passed into game_load_game_special().**
///
/// @remark Only used when multiple ROMs are required.
///
typedef enum SPECIAL_GAME_TYPE
{
  /// @brief Game Type BSX
  SPECIAL_GAME_TYPE_BSX,

  /// @brief Game Type BSX slotted
  SPECIAL_GAME_TYPE_BSX_SLOTTED,

  /// @brief Game Type sufami turbo
  SPECIAL_GAME_TYPE_SUFAMI_TURBO,

  /// @brief Game Type super game boy
  SPECIAL_GAME_TYPE_SUPER_GAME_BOY,
} SPECIAL_GAME_TYPE;
//------------------------------------------------------------------------------

//==============================================================================
/// @brief **Game Memory**
///
typedef enum GAME_MEMORY
{
  /// @brief Passed to game_get_memory_data/size(). If the memory type doesn't apply
  /// to the implementation NULL/0 can be returned.
  GAME_MEMORY_MASK = 0xff,

  /// @brief Regular save ram.
  ///
  /// This ram is usually found on a game cartridge, backed
  /// up by a battery. If save game data is too complex for a single memory
  /// buffer, the SYSTEM_DIRECTORY environment callback can be used.
  GAME_MEMORY_SAVE_RAM = 0,

  /// @brief Some games have a built-in clock to keep track of time.
  ///
  /// This memory is usually just a couple of bytes to keep track of time.
  GAME_MEMORY_RTC = 1,

  /// @brief System ram lets a frontend peek into a game systems main RAM
  GAME_MEMORY_SYSTEM_RAM = 2,

  /// @brief Video ram lets a frontend peek into a game systems video RAM (VRAM)
  GAME_MEMORY_VIDEO_RAM = 3,

  /// @brief Special memory type
  GAME_MEMORY_SNES_BSX_RAM = ((1 << 8) | GAME_MEMORY_SAVE_RAM),

  /// @brief Special memory type
  GAME_MEMORY_SNES_BSX_PRAM = ((2 << 8) | GAME_MEMORY_SAVE_RAM),

  /// @brief Special memory type
  GAME_MEMORY_SNES_SUFAMI_TURBO_A_RAM = ((3 << 8) | GAME_MEMORY_SAVE_RAM),

  /// @brief Special memory type
  GAME_MEMORY_SNES_SUFAMI_TURBO_B_RAM = ((4 << 8) | GAME_MEMORY_SAVE_RAM),

  /// @brief Special memory type
  GAME_MEMORY_SNES_GAME_BOY_RAM = ((5 << 8) | GAME_MEMORY_SAVE_RAM),

  /// @brief Special memory type
  GAME_MEMORY_SNES_GAME_BOY_RTC = ((6 << 8) | GAME_MEMORY_RTC),
} GAME_MEMORY;
//------------------------------------------------------------------------------

//==============================================================================
/// @brief **ID values for SIMD CPU features**
typedef enum GAME_SIMD
{
  /// @brief SIMD CPU SSE
  GAME_SIMD_SSE = (1 << 0),

  /// @brief SIMD CPU SSE2
  GAME_SIMD_SSE2 = (1 << 1),

  /// @brief SIMD CPU VMX
  GAME_SIMD_VMX = (1 << 2),

  /// @brief SIMD CPU VMX128
  GAME_SIMD_VMX128 = (1 << 3),

  /// @brief SIMD CPU AVX
  GAME_SIMD_AVX = (1 << 4),

  /// @brief SIMD CPU NEON
  GAME_SIMD_NEON = (1 << 5),

  /// @brief SIMD CPU SSE3
  GAME_SIMD_SSE3 = (1 << 6),

  /// @brief SIMD CPU SSSE3
  GAME_SIMD_SSSE3 = (1 << 7),

  /// @brief SIMD CPU MMX
  GAME_SIMD_MMX = (1 << 8),

  /// @brief SIMD CPU MMXEXT
  GAME_SIMD_MMXEXT = (1 << 9),

  /// @brief SIMD CPU SSE4
  GAME_SIMD_SSE4 = (1 << 10),

  /// @brief SIMD CPU SSE42
  GAME_SIMD_SSE42 = (1 << 11),

  /// @brief SIMD CPU AVX2
  GAME_SIMD_AVX2 = (1 << 12),

  /// @brief SIMD CPU VFPU
  GAME_SIMD_VFPU = (1 << 13),
} GAME_SIMD;
//------------------------------------------------------------------------------

//@}

//--==----==----==----==----==----==----==----==----==----==----==----==----==--
/// \defgroup cpp_kodi_addon_game_Defs_InputTypes 7. Input types
/// \ingroup cpp_kodi_addon_game_Defs
/// @brief **Input types**
///
//@{

//==============================================================================
/// @brief
typedef enum GAME_INPUT_EVENT_SOURCE
{
  /// @brief
  GAME_INPUT_EVENT_DIGITAL_BUTTON,

  /// @brief
  GAME_INPUT_EVENT_ANALOG_BUTTON,

  /// @brief
  GAME_INPUT_EVENT_AXIS,

  /// @brief
  GAME_INPUT_EVENT_ANALOG_STICK,

  /// @brief
  GAME_INPUT_EVENT_ACCELEROMETER,

  /// @brief
  GAME_INPUT_EVENT_KEY,

  /// @brief
  GAME_INPUT_EVENT_RELATIVE_POINTER,

  /// @brief
  GAME_INPUT_EVENT_ABSOLUTE_POINTER,

  /// @brief
  GAME_INPUT_EVENT_MOTOR,
} GAME_INPUT_EVENT_SOURCE;
//------------------------------------------------------------------------------

//==============================================================================
/// @brief
typedef enum GAME_KEY_MOD
{
  /// @brief
  GAME_KEY_MOD_NONE = 0x0000,

  /// @brief
  GAME_KEY_MOD_SHIFT = 0x0001,

  /// @brief
  GAME_KEY_MOD_CTRL = 0x0002,

  /// @brief
  GAME_KEY_MOD_ALT = 0x0004,

  /// @brief
  GAME_KEY_MOD_META = 0x0008,

  /// @brief
  GAME_KEY_MOD_SUPER = 0x0010,

  /// @brief
  GAME_KEY_MOD_NUMLOCK = 0x0100,

  /// @brief
  GAME_KEY_MOD_CAPSLOCK = 0x0200,

  /// @brief
  GAME_KEY_MOD_SCROLLOCK = 0x0400,
} GAME_KEY_MOD;
//------------------------------------------------------------------------------

//==============================================================================
/// @brief Type of port on the virtual game console
typedef enum GAME_PORT_TYPE
{
  /// @brief Game port unknown
  GAME_PORT_UNKNOWN,

  /// @brief Game port Keyboard
  GAME_PORT_KEYBOARD,

  /// @brief Game port mouse
  GAME_PORT_MOUSE,

  /// @brief Game port controller
  GAME_PORT_CONTROLLER,
} GAME_PORT_TYPE;
//------------------------------------------------------------------------------

/*! \cond PRIVATE */
/*!
  * @brief "C" Game add-on controller layout.
  *
  * Structure used to interface in "C" between Kodi and Addon.
  *
  * See @ref AddonGameControllerLayout for description of values.
  */
typedef struct game_controller_layout
{
  char* controller_id;
  bool provides_input; // False for multitaps
  char** digital_buttons;
  unsigned int digital_button_count;
  char** analog_buttons;
  unsigned int analog_button_count;
  char** analog_sticks;
  unsigned int analog_stick_count;
  char** accelerometers;
  unsigned int accelerometer_count;
  char** keys;
  unsigned int key_count;
  char** rel_pointers;
  unsigned int rel_pointer_count;
  char** abs_pointers;
  unsigned int abs_pointer_count;
  char** motors;
  unsigned int motor_count;
} ATTRIBUTE_PACKED game_controller_layout;
 /*! \endcond */

//==============================================================================
/// @brief
struct AddonGameControllerLayout
{
  /*! \cond PRIVATE */
  explicit AddonGameControllerLayout() = default;
  AddonGameControllerLayout(const game_controller_layout& layout)
  {
    controller_id = layout.controller_id;
    provides_input = layout.provides_input;
    for (unsigned int i = 0; i < layout.digital_button_count; ++i)
      digital_buttons.push_back(layout.digital_buttons[i]);
    for (unsigned int i = 0; i < layout.analog_button_count; ++i)
      analog_buttons.push_back(layout.analog_buttons[i]);
    for (unsigned int i = 0; i < layout.analog_stick_count; ++i)
      analog_sticks.push_back(layout.analog_sticks[i]);
    for (unsigned int i = 0; i < layout.accelerometer_count; ++i)
      accelerometers.push_back(layout.accelerometers[i]);
    for (unsigned int i = 0; i < layout.key_count; ++i)
      keys.push_back(layout.keys[i]);
    for (unsigned int i = 0; i < layout.rel_pointer_count; ++i)
      rel_pointers.push_back(layout.rel_pointers[i]);
    for (unsigned int i = 0; i < layout.abs_pointer_count; ++i)
      abs_pointers.push_back(layout.abs_pointers[i]);
    for (unsigned int i = 0; i < layout.motor_count; ++i)
      motors.push_back(layout.motors[i]);
  }
  /*! \endcond */

  /// @brief
  std::string controller_id;

  /// @brief False for multitaps
  bool provides_input;

  /// @brief
  std::vector<std::string> digital_buttons;

  /// @brief
  std::vector<std::string> analog_buttons;

  /// @brief
  std::vector<std::string> analog_sticks;

  /// @brief
  std::vector<std::string> accelerometers;

  /// @brief
  std::vector<std::string> keys;

  /// @brief
  std::vector<std::string> rel_pointers;

  /// @brief
  std::vector<std::string> abs_pointers;

  /// @brief
  std::vector<std::string> motors;
};
//------------------------------------------------------------------------------

struct game_input_port;

//==============================================================================
/// @brief Device that can provide input
typedef struct game_input_device
{
  /// @brief ID used in the Kodi controller API
  const char* controller_id;

  /// @brief
  const char* port_address;

  /// @brief
  game_input_port* available_ports;

  /// @brief
  unsigned int port_count;
} ATTRIBUTE_PACKED game_input_device;
//------------------------------------------------------------------------------

//==============================================================================
/// @brief Port that can provide input
///
/// Ports can accept multiple devices and devices can have multiple ports, so
/// the topology of possible configurations is a tree structure of alternating
/// port and device nodes.
///
typedef struct game_input_port
{
  /// @brief
  GAME_PORT_TYPE type;

  /// @brief Required for GAME_PORT_CONTROLLER type
  const char* port_id;

  /// @brief
  game_input_device* accepted_devices;

  /// @brief
  unsigned int device_count;
} ATTRIBUTE_PACKED game_input_port;
//------------------------------------------------------------------------------

//==============================================================================
/// @brief The input topology is the possible ways to connect input devices
///
/// This represents the logical topology, which is the possible connections that
/// the game client's logic can handle. It is strictly a subset of the physical
/// topology. Loops are not allowed.
///
typedef struct game_input_topology
{
  /// @brief The list of ports on the virtual game console
  game_input_port *ports;

  /// @brief The number of ports
  unsigned int port_count;

  /// @brief A limit on the number of input-providing devices, or -1 for no limit
  int player_limit;
} ATTRIBUTE_PACKED game_input_topology;
//------------------------------------------------------------------------------

//==============================================================================
/// @brief
typedef struct game_digital_button_event
{
  /// @brief
  bool pressed;
} ATTRIBUTE_PACKED game_digital_button_event;
//------------------------------------------------------------------------------

//==============================================================================
/// @brief
typedef struct game_analog_button_event
{
  /// @brief
  float magnitude;
} ATTRIBUTE_PACKED game_analog_button_event;
//------------------------------------------------------------------------------

//==============================================================================
/// @brief
typedef struct game_axis_event
{
  /// @brief
  float position;
} ATTRIBUTE_PACKED game_axis_event;
//------------------------------------------------------------------------------

//==============================================================================
/// @brief
typedef struct game_analog_stick_event
{
  /// @brief
  float x;

  /// @brief
  float y;
} ATTRIBUTE_PACKED game_analog_stick_event;
//------------------------------------------------------------------------------

//==============================================================================
/// @brief
typedef struct game_accelerometer_event
{
  /// @brief
  float x;

  /// @brief
  float y;

  /// @brief
  float z;
} ATTRIBUTE_PACKED game_accelerometer_event;
//------------------------------------------------------------------------------

//==============================================================================
/// @brief
typedef struct game_key_event
{
  /// @brief
  bool pressed;

  /// @brief If the keypress generates a printing character
  ///
  /// The unicode value contains the character generated. If the key is a
  /// non-printing character, e.g. a function or arrow key, the unicode value
  /// is zero.
  uint32_t unicode;

  /// @brief
  GAME_KEY_MOD modifiers;
} ATTRIBUTE_PACKED game_key_event;
//------------------------------------------------------------------------------

//==============================================================================
/// @brief
typedef struct game_rel_pointer_event
{
  /// @brief
  int x;

  /// @brief
  int y;
} ATTRIBUTE_PACKED game_rel_pointer_event;
//------------------------------------------------------------------------------

//==============================================================================
/// @brief
typedef struct game_abs_pointer_event
{
  /// @brief
  bool pressed;

  /// @brief
  float x;

  /// @brief
  float y;
} ATTRIBUTE_PACKED game_abs_pointer_event;
//------------------------------------------------------------------------------

//==============================================================================
/// @brief
typedef struct game_motor_event
{
  /// @brief
  float magnitude;
} ATTRIBUTE_PACKED game_motor_event;
//------------------------------------------------------------------------------

//==============================================================================
/// @brief
typedef struct game_input_event
{
  /// @brief
  GAME_INPUT_EVENT_SOURCE type;

  /// @brief
  const char* controller_id;

  /// @brief
  GAME_PORT_TYPE port_type;

  /// @brief
  const char* port_address;

  /// @brief
  const char* feature_name;
  union {
    /// @brief
    struct game_digital_button_event digital_button;

    /// @brief
    struct game_analog_button_event analog_button;

    /// @brief
    struct game_axis_event axis;

    /// @brief
    struct game_analog_stick_event analog_stick;

    /// @brief
    struct game_accelerometer_event accelerometer;

    /// @brief
    struct game_key_event key;

    /// @brief
    struct game_rel_pointer_event rel_pointer;

    /// @brief
    struct game_abs_pointer_event abs_pointer;

    /// @brief
    struct game_motor_event motor;
  };
} ATTRIBUTE_PACKED game_input_event;
//------------------------------------------------------------------------------

//@}

//--==----==----==----==----==----==----==----==----==----==----==----==----==--
/// \defgroup cpp_kodi_addon_game_Defs_EnvironmentTypes 8. Environment types
/// \ingroup cpp_kodi_addon_game_Defs
/// @brief **Environment types**
///
//@{

//==============================================================================
/// @brief Game system timing
///
struct game_system_timing
{
  /// @brief FPS of video content.
  double fps;

  /// @brief Sampling rate of audio.
  double sample_rate;
};
//------------------------------------------------------------------------------

//@}


//--==----==----==----==----==----==----==----==----==----==----==----==----==--

/*!
 * @brief Game properties
 *
  * Not to be used outside this header.
 */
typedef struct AddonProps_Game
{
  /*!
    * The path of the game client being loaded.
    */
  const char* game_client_dll_path;

  /*!
    * Paths to proxy DLLs used to load the game client.
    */
  const char** proxy_dll_paths;

  /*!
    * Number of proxy DLL paths provided.
    */
  unsigned int proxy_dll_count;

  /*!
  * The "system" directories of the frontend. These directories can be used to
  * store system-specific ROMs such as BIOSes, configuration data, etc.
  */
  const char** resource_directories;

  /*!
   * Number of resource directories provided
   */
  unsigned int resource_directory_count;

  /*!
   * The writable directory of the frontend. This directory can be used to store
   * SRAM, memory cards, high scores, etc, if the game client cannot use the
   * regular memory interface, GetMemoryData().
   */
  const char* profile_directory;

  /*!
   * The value of the <supports_vfs> property from addon.xml
   */
  bool supports_vfs;

  /*!
   * The extensions in the <extensions> property from addon.xml
   */
  const char** extensions;

  /*!
   * Number of extensions provided
   */
  unsigned int extension_count;
} AddonProps_Game;

typedef AddonProps_Game game_client_properties;

/*! Structure to transfer the methods from kodi_game_dll.h to Kodi */

struct AddonInstance_Game;

/*!
 * @brief Game callbacks
 *
 * Not to be used outside this header.
 */
typedef struct AddonToKodiFuncTable_Game
{
  KODI_HANDLE kodiInstance;

  void (*CloseGame)(void* kodiInstance);
  void* (*OpenStream)(void*, const game_stream_properties*);
  bool (*GetStreamBuffer)(void*, void*, unsigned int, unsigned int, game_stream_buffer*);
  void (*AddStreamData)(void*, void*, const game_stream_packet*);
  void (*ReleaseStreamBuffer)(void*, void*, game_stream_buffer*);
  void (*CloseStream)(void*, void*);
  game_proc_address_t (*HwGetProcAddress)(void* kodiInstance, const char* symbol);
  bool (*InputEvent)(void* kodiInstance, const game_input_event* event);
} AddonToKodiFuncTable_Game;

/*!
 * @brief Game function hooks
 *
 * Not to be used outside this header.
 */
typedef struct KodiToAddonFuncTable_Game
{
  kodi::addon::CInstanceGame* addonInstance;

  GAME_ERROR(__cdecl* LoadGame)(const AddonInstance_Game*, const char*);
  GAME_ERROR(__cdecl* LoadGameSpecial)
  (const AddonInstance_Game*, SPECIAL_GAME_TYPE, const char**, size_t);
  GAME_ERROR(__cdecl* LoadStandalone)(const AddonInstance_Game*);
  GAME_ERROR(__cdecl* UnloadGame)(const AddonInstance_Game*);
  GAME_ERROR(__cdecl* GetGameTiming)(const AddonInstance_Game*, game_system_timing*);
  GAME_REGION(__cdecl* GetRegion)(const AddonInstance_Game*);
  bool(__cdecl* RequiresGameLoop)(const AddonInstance_Game*);
  GAME_ERROR(__cdecl* RunFrame)(const AddonInstance_Game*);
  GAME_ERROR(__cdecl* Reset)(const AddonInstance_Game*);
  GAME_ERROR(__cdecl* HwContextReset)(const AddonInstance_Game*);
  GAME_ERROR(__cdecl* HwContextDestroy)(const AddonInstance_Game*);
  bool(__cdecl* HasFeature)(const AddonInstance_Game*, const char*, const char*);
  game_input_topology*(__cdecl* GetTopology)(const AddonInstance_Game*);
  void(__cdecl* FreeTopology)(const AddonInstance_Game*, game_input_topology*);
  void(__cdecl* SetControllerLayouts)(const AddonInstance_Game*,
                                      const game_controller_layout*,
                                      unsigned int);
  bool(__cdecl* EnableKeyboard)(const AddonInstance_Game*, bool, const char*);
  bool(__cdecl* EnableMouse)(const AddonInstance_Game*, bool, const char*);
  bool(__cdecl* ConnectController)(const AddonInstance_Game*, bool, const char*, const char*);
  bool(__cdecl* InputEvent)(const AddonInstance_Game*, const game_input_event*);
  size_t(__cdecl* SerializeSize)(const AddonInstance_Game*);
  GAME_ERROR(__cdecl* Serialize)(const AddonInstance_Game*, uint8_t*, size_t);
  GAME_ERROR(__cdecl* Deserialize)(const AddonInstance_Game*, const uint8_t*, size_t);
  GAME_ERROR(__cdecl* CheatReset)(const AddonInstance_Game*);
  GAME_ERROR(__cdecl* GetMemory)(const AddonInstance_Game*, GAME_MEMORY, uint8_t**, size_t*);
  GAME_ERROR(__cdecl* SetCheat)(const AddonInstance_Game*, unsigned int, bool, const char*);
} KodiToAddonFuncTable_Game;

/*!
 * @brief Game instance
 *
 * Not to be used outside this header.
 */
typedef struct AddonInstance_Game
{
  AddonProps_Game props;
  AddonToKodiFuncTable_Game toKodi;
  KodiToAddonFuncTable_Game toAddon;
} AddonInstance_Game;

} /* extern "C" */

namespace kodi
{
namespace addon
{

//==============================================================================
///
/// \addtogroup cpp_kodi_addon_game
/// @brief \cpp_class{ kodi::addon::CInstanceGame }
/// **Game add-on instance**
///
/// This class is created at addon by Kodi.
///
//------------------------------------------------------------------------------
class ATTRIBUTE_HIDDEN CInstanceGame : public IAddonInstance
{
public:
  //============================================================================
  ///
  /// @defgroup cpp_kodi_addon_game_Base 1. Basic functions
  /// @ingroup cpp_kodi_addon_game
  /// @brief **Functions to manage the addon and get basic information about it**
  ///
  ///
  //@{

  //============================================================================
  ///
  /// @brief Game class constructor
  ///
  /// Used by an add-on that only supports only Game and only in one instance.
  ///
  /// This class is created at addon by Kodi.
  ///
  ///
  /// --------------------------------------------------------------------------
  ///
  ///
  /// **Here's example about the use of this:**
  /// ~~~~~~~~~~~~~{.cpp}
  /// #include <kodi/addon-instance/Game.h>
  /// ...
  ///
  /// class ATTRIBUTE_HIDDEN CGameExample
  ///   : public kodi::addon::CAddonBase,
  ///     public kodi::addon::CInstanceGame
  /// {
  /// public:
  ///   CGameExample()
  ///   {
  ///   }
  ///
  ///   virtual ~CGameExample();
  ///   {
  ///   }
  ///
  ///   ...
  /// };
  ///
  /// ADDONCREATOR(CGameExample)
  /// ~~~~~~~~~~~~~
  ///
  CInstanceGame() : IAddonInstance(ADDON_INSTANCE_GAME, GetKodiTypeVersion(ADDON_INSTANCE_GAME))
  {
    if (CAddonBase::m_interface->globalSingleInstance != nullptr)
      throw std::logic_error("kodi::addon::CInstanceGame: Creation of more as one in single "
                             "instance way is not allowed!");

    SetAddonStruct(CAddonBase::m_interface->firstKodiInstance);
    CAddonBase::m_interface->globalSingleInstance = this;
  }
  //----------------------------------------------------------------------------

  //============================================================================
  ///
  /// @brief Destructor
  ///
  ~CInstanceGame() override = default;
  //----------------------------------------------------------------------------

  //============================================================================
  ///
  /// @brief **Callback to Kodi Function**<br>The path of the game client being loaded.
  ///
  /// @return the used game client Dll path
  ///
  /// @remarks Only called from addon itself
  ///
  std::string GameClientDllPath() const
  {
    return m_instanceData->props.game_client_dll_path;
  }
  //----------------------------------------------------------------------------

  //============================================================================
  ///
  /// @brief **Callback to Kodi Function**<br>Paths to proxy DLLs used to load the game client.
  ///
  /// @param[out] paths vector list to store available dll paths
  /// @return true if success and dll paths present
  ///
  /// @remarks Only called from addon itself
  ///
  bool ProxyDllPaths(std::vector<std::string>& paths)
  {
    for (unsigned int i = 0; i < m_instanceData->props.proxy_dll_count; ++i)
    {
      if (m_instanceData->props.proxy_dll_paths[i] != nullptr)
        paths.push_back(m_instanceData->props.proxy_dll_paths[i]);
    }
    return !paths.empty();
  }
  //----------------------------------------------------------------------------

  //============================================================================
  ///
  /// @brief **Callback to Kodi Function**<br>The "system" directories of the frontend
  ///
  /// These directories can be used to store system-specific ROMs such as
  /// BIOSes, configuration data, etc.
  ///
  /// @return the used resource directory
  ///
  /// @remarks Only called from addon itself
  ///
  bool ResourceDirectories(std::vector<std::string>& dirs)
  {
    for (unsigned int i = 0; i < m_instanceData->props.resource_directory_count; ++i)
    {
      if (m_instanceData->props.resource_directories[i] != nullptr)
        dirs.push_back(m_instanceData->props.resource_directories[i]);
    }
    return !dirs.empty();
  }
  //----------------------------------------------------------------------------

  //============================================================================
  ///
  /// @brief **Callback to Kodi Function**<br>The writable directory of the frontend
  ///
  /// This directory can be used to store SRAM, memory cards, high scores,
  /// etc, if the game client cannot use the regular memory interface,
  /// GetMemoryData().
  ///
  /// @return the used profile directory
  ///
  /// @remarks Only called from addon itself
  ///
  std::string ProfileDirectory() const
  {
    return m_instanceData->props.profile_directory;
  }
  //----------------------------------------------------------------------------

  //============================================================================
  ///
  /// @brief **Callback to Kodi Function**<br>The value of the <supports_vfs> property from addon.xml
  ///
  /// @return true if VFS is supported
  ///
  /// @remarks Only called from addon itself
  ///
  bool SupportsVFS() const
  {
    return m_instanceData->props.supports_vfs;
  }
  //----------------------------------------------------------------------------

  //============================================================================
  ///
  /// @brief **Callback to Kodi Function**<br>The extensions in the <extensions> property from addon.xml
  ///
  /// @param[out] extensions vector list to store available extension
  /// @return true if success and extensions present
  ///
  /// @remarks Only called from addon itself
  ///
  bool Extensions(std::vector<std::string>& extensions)
  {
    for (unsigned int i = 0; i < m_instanceData->props.extension_count; ++i)
    {
      if (m_instanceData->props.extensions[i] != nullptr)
        extensions.push_back(m_instanceData->props.extensions[i]);
    }
    return !extensions.empty();
  }
  //----------------------------------------------------------------------------

  //@}

//--==----==----==----==----==----==----==----==----==----==----==----==----==--

  //============================================================================
  ///
  /// @defgroup cpp_kodi_addon_game_Operation 2. Game operations
  /// @ingroup cpp_kodi_addon_game
  /// @brief **Game operations**
  ///
  /// These are mandatory functions for using this addon to get the available
  /// channels.
  ///
  //@{

  //============================================================================
  ///
  /// @brief Load a game
  ///
  /// @param[in] url The URL to load
  /// @return the error, or @ref GAME_ERROR_NO_ERROR if the game was loaded
  ///
  virtual GAME_ERROR LoadGame(const std::string& url)
  {
    return GAME_ERROR_NOT_IMPLEMENTED;
  }
  //----------------------------------------------------------------------------

  //============================================================================
  ///
  /// @brief Load a game that requires multiple files
  ///
  /// @param[in] type The game type
  /// @param[in] urls An array of urls
  /// @return the error, or @ref GAME_ERROR_NO_ERROR if the game was loaded
  ///
  virtual GAME_ERROR LoadGameSpecial(SPECIAL_GAME_TYPE type, const std::vector<std::string>& urls)
  {
    return GAME_ERROR_NOT_IMPLEMENTED;
  }
  //----------------------------------------------------------------------------

  //============================================================================
  ///
  /// @brief 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>
  ///
  /// @return the error, or @ref GAME_ERROR_NO_ERROR if the game add-on was loaded
  ///
  virtual GAME_ERROR LoadStandalone()
  {
    return GAME_ERROR_NOT_IMPLEMENTED;
  }
  //----------------------------------------------------------------------------

  //============================================================================
  ///
  /// @brief Unload the current game
  ///
  /// Unloads a currently loaded game
  ///
  /// @return the error, or @ref GAME_ERROR_NO_ERROR if the game was unloaded
  ///
  virtual GAME_ERROR UnloadGame()
  {
    return GAME_ERROR_NOT_IMPLEMENTED;
  }
  //----------------------------------------------------------------------------

  //============================================================================
  ///
  /// @brief Get timing information about the loaded game
  ///
  /// @param[out] timing_info The info structure to fill
  ///
  /// @return the error, or @ref GAME_ERROR_NO_ERROR if info was filled
  ///
  virtual GAME_ERROR GetGameTiming(game_system_timing& timing_info)
  {
    return GAME_ERROR_NOT_IMPLEMENTED;
  }
  //----------------------------------------------------------------------------

  //============================================================================
  ///
  /// @brief Get region of the loaded game
  ///
  /// @return the region, or @ref GAME_REGION_UNKNOWN if unknown or no game is loaded
  ///
  virtual GAME_REGION GetRegion()
  {
    return GAME_REGION_UNKNOWN;
  }
  //----------------------------------------------------------------------------

  //============================================================================
  ///
  /// @brief 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.
  ///
  /// @return true if the frontend should provide a game loop, false otherwise
  ///
  virtual bool RequiresGameLoop()
  {
    return false;
  }
  //----------------------------------------------------------------------------

  //============================================================================
  ///
  /// @brief Run a single frame for add-ons that use a game loop
  ///
  /// @return the error, or @ref GAME_ERROR_NO_ERROR if there was no error
  ///
  virtual GAME_ERROR RunFrame()
  {
    return GAME_ERROR_NOT_IMPLEMENTED;
  }
  //----------------------------------------------------------------------------

  //============================================================================
  ///
  /// @brief Reset the current game
  ///
  /// @return the error, or @ref GAME_ERROR_NO_ERROR if the game was reset
  ///
  virtual GAME_ERROR Reset()
  {
    return GAME_ERROR_NOT_IMPLEMENTED;
  }
  //----------------------------------------------------------------------------

  //==========================================================================
  ///
  /// @brief **Callback to Kodi Function**<br>Requests the frontend to stop the current game
  ///
  /// @remarks Only called from addon itself
  ///
  void CloseGame(void) { m_instanceData->toKodi.CloseGame(m_instanceData->toKodi.kodiInstance); }
  //----------------------------------------------------------------------------

  //============================================================================
  ///
  /// @defgroup cpp_kodi_addon_game_Operation_CStream Class: CStream
  /// @ingroup cpp_kodi_addon_game_Operation
  /// @brief \cpp_class{ kodi::addon::CInstanceGame::CStream }
  /// **Game stream handler**
  ///
  /// This class will be integrated into the addon, which can then open it if
  /// necessary for the processing of an audio or video stream.
  ///
  ///
  /// @note Callback to Kodi class
  //@{
  class CStream
  {
  public:
    CStream() = default;

    CStream(const game_stream_properties& properties)
    {
      Open(properties);
    }

    ~CStream()
    {
      Close();
    }

    //==========================================================================
    ///
    /// @ingroup cpp_kodi_addon_game_Operation_CStream
    /// @brief Create a stream for gameplay data
    ///
    /// @param[in] properties The stream properties
    /// @return A stream handle, or `nullptr` on failure
    ///
    /// @remarks Only called from addon itself
    ///
    bool Open(const game_stream_properties& properties)
    {
      if (!CAddonBase::m_interface->globalSingleInstance)
        return false;

      if (m_handle)
      {
        kodi::Log(ADDON_LOG_INFO, "kodi::addon::CInstanceGame::CStream already becomes reopened");
        Close();
      }

      AddonToKodiFuncTable_Game& cb =
          static_cast<CInstanceGame*>(CAddonBase::m_interface->globalSingleInstance)
              ->m_instanceData->toKodi;
      m_handle = cb.OpenStream(cb.kodiInstance, &properties);
      return m_handle != nullptr;
    }
    //--------------------------------------------------------------------------

    //==========================================================================
    ///
    /// @ingroup cpp_kodi_addon_game_Operation_CStream
    /// @brief Free the specified stream
    ///
    /// @remarks Only called from addon itself
    ///
    void Close()
    {
      if (!m_handle || !CAddonBase::m_interface->globalSingleInstance)
        return;

      AddonToKodiFuncTable_Game& cb =
          static_cast<CInstanceGame*>(CAddonBase::m_interface->globalSingleInstance)
              ->m_instanceData->toKodi;
      cb.CloseStream(cb.kodiInstance, m_handle);
      m_handle = nullptr;
    }
    //--------------------------------------------------------------------------

    //==========================================================================
    ///
    /// @ingroup cpp_kodi_addon_game_Operation_CStream
    /// @brief Get a buffer for zero-copy stream data
    ///
    /// @param[in] width The framebuffer width, or 0 for no width specified
    /// @param[in] height The framebuffer height, or 0 for no height specified
    /// @param[out] buffer The buffer, or unmodified if false is returned
    /// @return True if buffer was set, false otherwise
    ///
    /// @note If this returns true, buffer must be freed using \ref ReleaseBuffer().
    ///
    /// @remarks Only called from addon itself
    ///
    bool GetBuffer(unsigned int width, unsigned int height, game_stream_buffer& buffer)
    {
      if (!m_handle || !CAddonBase::m_interface->globalSingleInstance)
        return false;

      AddonToKodiFuncTable_Game& cb =
          static_cast<CInstanceGame*>(CAddonBase::m_interface->globalSingleInstance)
              ->m_instanceData->toKodi;
      return cb.GetStreamBuffer(cb.kodiInstance, m_handle, width, height, &buffer);
    }
    //--------------------------------------------------------------------------

    //==========================================================================
    ///
    /// @ingroup cpp_kodi_addon_game_Operation_CStream
    /// @brief Add a data packet to a stream
    ///
    /// @param[in] packet The data packet
    ///
    /// @remarks Only called from addon itself
    ///
    void AddData(const game_stream_packet& packet)
    {
      if (!m_handle || !CAddonBase::m_interface->globalSingleInstance)
        return;

      AddonToKodiFuncTable_Game& cb =
          static_cast<CInstanceGame*>(CAddonBase::m_interface->globalSingleInstance)
              ->m_instanceData->toKodi;
      cb.AddStreamData(cb.kodiInstance, m_handle, &packet);
    }
    //--------------------------------------------------------------------------

    //==========================================================================
    ///
    /// @ingroup cpp_kodi_addon_game_Operation_CStream
    /// @brief Free an allocated buffer
    ///
    /// @param[in] buffer The buffer returned from GetStreamBuffer()
    ///
    /// @remarks Only called from addon itself
    ///
    void ReleaseBuffer(game_stream_buffer& buffer)
    {
      if (!m_handle || !CAddonBase::m_interface->globalSingleInstance)
        return;

      AddonToKodiFuncTable_Game& cb =
          static_cast<CInstanceGame*>(CAddonBase::m_interface->globalSingleInstance)
              ->m_instanceData->toKodi;
      cb.ReleaseStreamBuffer(cb.kodiInstance, m_handle, &buffer);
    }
    //--------------------------------------------------------------------------

    //==========================================================================
    ///
    /// @ingroup cpp_kodi_addon_game_Operation_CStream
    /// @brief To check stream open was OK, e.g. after use of constructor
    ///
    /// @return true if stream was successfully opened
    ///
    /// @remarks Only called from addon itself
    ///
    bool IsOpen() const { return m_handle != nullptr; }
    //--------------------------------------------------------------------------

  private:
    void* m_handle = nullptr;
  };
  //@}

  //@}

//--==----==----==----==----==----==----==----==----==----==----==----==----==--

  //============================================================================
  ///
  /// @defgroup cpp_kodi_addon_game_HardwareRendering 3. Hardware rendering operations
  /// @ingroup cpp_kodi_addon_game
  /// @brief **Hardware rendering operations**
  ///
  //@{

  //============================================================================
  ///
  /// @brief Invalidates the current HW context and reinitializes GPU resources
  ///
  /// Any GL state is lost, and must not be deinitialized explicitly.
  ///
  /// @return the error, or @ref GAME_ERROR_NO_ERROR if the HW context was reset
  ///
  virtual GAME_ERROR HwContextReset()
  {
    return GAME_ERROR_NOT_IMPLEMENTED;
  }
  //----------------------------------------------------------------------------

  //============================================================================
  ///
  /// @brief Called before the context is destroyed
  ///
  /// Resources can be deinitialized at this step.
  ///
  /// @return the error, or @ref GAME_ERROR_NO_ERROR if the HW context was destroyed
  ///
  virtual GAME_ERROR HwContextDestroy()
  {
    return GAME_ERROR_NOT_IMPLEMENTED;
  }

  //============================================================================
  ///
  /// @brief **Callback to Kodi Function**<br>Get a symbol from the hardware context
  ///
  /// @param[in] sym The symbol's name
  ///
  /// @return A function pointer for the specified symbol
  ///
  /// @remarks Only called from addon itself
  ///
  game_proc_address_t HwGetProcAddress(const char* sym)
  {
    return m_instanceData->toKodi.HwGetProcAddress(m_instanceData->toKodi.kodiInstance, sym);
  }
  //----------------------------------------------------------------------------

  //@}

//--==----==----==----==----==----==----==----==----==----==----==----==----==--

  //============================================================================
  ///
  /// @defgroup cpp_kodi_addon_game_InputOperations 4. Input operations
  /// @ingroup cpp_kodi_addon_game
  /// @brief **Input operations**
  ///
  //@{

  //============================================================================
  ///
  /// @brief 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.
  ///
  /// @param[in] controller_id The ID of the controller profile
  /// @param[in] feature_name The name of a feature in that profile
  /// @return true if input is accepted for the feature, false otherwise
  ///
  virtual bool HasFeature(const std::string& controller_id, const std::string& feature_name)
  {
    return false;
  }
  //----------------------------------------------------------------------------

  //============================================================================
  ///
  /// @brief Get the input topology that specifies which controllers can be connected
  ///
  /// @return 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 @ref DEFAULT_PORT_ID constant.
  ///
  virtual game_input_topology* GetTopology()
  {
    return nullptr;
  }
  //----------------------------------------------------------------------------

  //============================================================================
  ///
  /// @brief Free the topology's resources
  ///
  /// @param[in] topology The topology returned by GetTopology()
    ///
  virtual void FreeTopology(game_input_topology* topology)
  {
  }
  //----------------------------------------------------------------------------

  //============================================================================
  ///
  /// @brief Set the layouts for known controllers
  ///
  /// @param[in] controllers The controller layouts
  ///
  /// After loading the input topology, the frontend will call this with
  /// controller layouts for all controllers discovered in the topology.
  ///
  virtual void SetControllerLayouts(const std::vector<AddonGameControllerLayout>& controllers)
  {
  }
  //----------------------------------------------------------------------------

  //============================================================================
  ///
  /// @brief Enable/disable keyboard input using the specified controller
  ///
  /// @param[in] enable True to enable input, false otherwise
  /// @param[in] controller_id The controller ID if enabling, or unused if disabling
  ///
  /// @return True if keyboard input was enabled, false otherwise
  ///
  virtual bool EnableKeyboard(bool enable, const std::string& controller_id)
  {
    return false;
  }
  //----------------------------------------------------------------------------

  //============================================================================
  ///
  /// @brief Enable/disable mouse input using the specified controller
  ///
  /// @param[in] enable True to enable input, false otherwise
  /// @param[in] controller_id The controller ID if enabling, or unused if disabling
  ///
  /// @return True if mouse input was enabled, false otherwise
  ///
  virtual bool EnableMouse(bool enable, const std::string& controller_id)
  {
    return false;
  }
  //--------------------------------------------------------------------------

  //==========================================================================
  ///
  /// @brief Connect/disconnect a controller to a port on the virtual game console
  ///
  /// @param[in] connect True to connect a controller, false to disconnect
  /// @param[in] port_address The address of the port
  /// @param[in] controller_id The controller ID if connecting, or unused if disconnecting
  /// @return True if the \p 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:
  ///
  /// ~~~~~~~~~~~~~{.xml}
  ///     <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.
  ///
  virtual bool ConnectController(bool connect,
                                 const std::string& port_address,
                                 const std::string& controller_id)
  {
    return false;
  }
  //----------------------------------------------------------------------------

  //============================================================================
  ///
  /// @brief Notify the add-on of an input event
  ///
  /// @param[in] event The input event
  ///
  /// @return true if the event was handled, false otherwise
  ///
  virtual bool InputEvent(const game_input_event& event)
  {
    return false;
  }
  //----------------------------------------------------------------------------

  //============================================================================
  ///
  /// @brief **Callback to Kodi Function**<br>Notify the port of an input event
  ///
  /// @param[in] event The input event
  /// @return true if the event was handled, false otherwise
  ///
  /// @note Input events can arrive for the following sources:
  ///   - \ref GAME_INPUT_EVENT_MOTOR
  ///
  /// @remarks Only called from addon itself
  ///
  bool KodiInputEvent(const game_input_event& event)
  {
    return m_instanceData->toKodi.InputEvent(m_instanceData->toKodi.kodiInstance, &event);
  }
  //----------------------------------------------------------------------------

  //@}

//--==----==----==----==----==----==----==----==----==----==----==----==----==--

  //============================================================================
  ///
  /// @defgroup cpp_kodi_addon_game_SerializationOperations 5. Serialization operations
  /// @ingroup cpp_kodi_addon_game
  /// @brief **Serialization operations**
  ///
  //@{

  //============================================================================
  ///
  /// @brief Get the number of bytes required to serialize the game
  ///
  /// @return the number of bytes, or 0 if serialization is not supported
  ///
  virtual size_t SerializeSize()
  {
    return 0;
  }
  //----------------------------------------------------------------------------

  //============================================================================
  ///
  /// @brief Serialize the state of the game
  ///
  /// @param[in] data The buffer receiving the serialized game data
  /// @param[in] size The size of the buffer
  ///
  /// @return the error, or @ref GAME_ERROR_NO_ERROR if the game was serialized into the buffer
  ///
  virtual GAME_ERROR Serialize(uint8_t* data, size_t size)
  {
    return GAME_ERROR_NOT_IMPLEMENTED;
  }
  //----------------------------------------------------------------------------

  //============================================================================
  ///
  /// @brief Deserialize the game from the given state
  ///
  /// @param[in] data A buffer containing the game's new state
  /// @param[in] size The size of the buffer
  ///
  /// @return the error, or @ref GAME_ERROR_NO_ERROR if the game deserialized
  ///
  virtual GAME_ERROR Deserialize(const uint8_t* data, size_t size)
  {
    return GAME_ERROR_NOT_IMPLEMENTED;
  }
  //----------------------------------------------------------------------------

  //@}

//--==----==----==----==----==----==----==----==----==----==----==----==----==--

  //============================================================================
  ///
  /// @defgroup cpp_kodi_addon_game_CheatOperations 6. Cheat operations
  /// @ingroup cpp_kodi_addon_game
  /// @brief **Cheat operations**
  ///
  //@{

  //============================================================================
  ///
  /// @brief Reset the cheat system
  ///
  /// @return the error, or @ref GAME_ERROR_NO_ERROR if the cheat system was reset
  ///
  virtual GAME_ERROR CheatReset()
  {
    return GAME_ERROR_NOT_IMPLEMENTED;
  }
  //----------------------------------------------------------------------------

  //============================================================================
  ///
  /// @brief Get a region of memory
  ///
  /// @param[in] type The type of memory to retrieve
  /// @param[in] data Set to the region of memory; must remain valid until UnloadGame() is called
  /// @param[in] size Set to the size of the region of memory
  ///
  /// @return the error, or @ref GAME_ERROR_NO_ERROR if data was set to a valid buffer
  ///
  virtual GAME_ERROR GetMemory(GAME_MEMORY type, uint8_t*& data, size_t& size)
  {
    return GAME_ERROR_NOT_IMPLEMENTED;
  }
  //----------------------------------------------------------------------------

  //============================================================================
  ///
  /// @brief Set a cheat code
  ///
  /// @param[in] index
  /// @param[in] enabled
  /// @param[in] code
  ///
  /// @return the error, or @ref GAME_ERROR_NO_ERROR if the cheat was set
  ///
  virtual GAME_ERROR SetCheat(unsigned int index, bool enabled, const std::string& code)
  {
    return GAME_ERROR_NOT_IMPLEMENTED;
  }
  //----------------------------------------------------------------------------

  //@}

private:
  void SetAddonStruct(KODI_HANDLE instance)
  {
    if (instance == nullptr)
      throw std::logic_error("kodi::addon::CInstanceGame: Creation with empty addon structure not"
                             "allowed, table must be given from Kodi!");

    m_instanceData = static_cast<AddonInstance_Game*>(instance);
    m_instanceData->toAddon.addonInstance = this;

    m_instanceData->toAddon.LoadGame = ADDON_LoadGame;
    m_instanceData->toAddon.LoadGameSpecial = ADDON_LoadGameSpecial;
    m_instanceData->toAddon.LoadStandalone = ADDON_LoadStandalone;
    m_instanceData->toAddon.UnloadGame = ADDON_UnloadGame;
    m_instanceData->toAddon.GetGameTiming = ADDON_GetGameTiming;
    m_instanceData->toAddon.GetRegion = ADDON_GetRegion;
    m_instanceData->toAddon.RequiresGameLoop = ADDON_RequiresGameLoop;
    m_instanceData->toAddon.RunFrame = ADDON_RunFrame;
    m_instanceData->toAddon.Reset = ADDON_Reset;

    m_instanceData->toAddon.HwContextReset = ADDON_HwContextReset;
    m_instanceData->toAddon.HwContextDestroy = ADDON_HwContextDestroy;

    m_instanceData->toAddon.HasFeature = ADDON_HasFeature;
    m_instanceData->toAddon.GetTopology = ADDON_GetTopology;
    m_instanceData->toAddon.FreeTopology = ADDON_FreeTopology;
    m_instanceData->toAddon.SetControllerLayouts = ADDON_SetControllerLayouts;
    m_instanceData->toAddon.EnableKeyboard = ADDON_EnableKeyboard;
    m_instanceData->toAddon.EnableMouse = ADDON_EnableMouse;
    m_instanceData->toAddon.ConnectController = ADDON_ConnectController;
    m_instanceData->toAddon.InputEvent = ADDON_InputEvent;

    m_instanceData->toAddon.SerializeSize = ADDON_SerializeSize;
    m_instanceData->toAddon.Serialize = ADDON_Serialize;
    m_instanceData->toAddon.Deserialize = ADDON_Deserialize;

    m_instanceData->toAddon.CheatReset = ADDON_CheatReset;
    m_instanceData->toAddon.GetMemory = ADDON_GetMemory;
    m_instanceData->toAddon.SetCheat = ADDON_SetCheat;
  }

  // --- Game operations ---------------------------------------------------------

  inline static GAME_ERROR ADDON_LoadGame(const AddonInstance_Game* instance, const char* url)
  {
    return instance->toAddon.addonInstance->LoadGame(url);
  }

  inline static GAME_ERROR ADDON_LoadGameSpecial(const AddonInstance_Game* instance,
                                                 SPECIAL_GAME_TYPE type,
                                                 const char** urls,
                                                 size_t urlCount)
  {
    std::vector<std::string> urlList;
    for (size_t i = 0; i < urlCount; ++i)
    {
      if (urls[i] != nullptr)
        urlList.push_back(urls[i]);
    }

    return instance->toAddon.addonInstance->LoadGameSpecial(type, urlList);
  }

  inline static GAME_ERROR ADDON_LoadStandalone(const AddonInstance_Game* instance)
  {
    return instance->toAddon.addonInstance->LoadStandalone();
  }

  inline static GAME_ERROR ADDON_UnloadGame(const AddonInstance_Game* instance)
  {
    return instance->toAddon.addonInstance->UnloadGame();
  }

  inline static GAME_ERROR ADDON_GetGameTiming(const AddonInstance_Game* instance,
                                               game_system_timing* timing_info)
  {
    return instance->toAddon.addonInstance->GetGameTiming(*timing_info);
  }

  inline static GAME_REGION ADDON_GetRegion(const AddonInstance_Game* instance)
  {
    return instance->toAddon.addonInstance->GetRegion();
  }

  inline static bool ADDON_RequiresGameLoop(const AddonInstance_Game* instance)
  {
    return instance->toAddon.addonInstance->RequiresGameLoop();
  }

  inline static GAME_ERROR ADDON_RunFrame(const AddonInstance_Game* instance)
  {
    return instance->toAddon.addonInstance->RunFrame();
  }

  inline static GAME_ERROR ADDON_Reset(const AddonInstance_Game* instance)
  {
    return instance->toAddon.addonInstance->Reset();
  }


  // --- Hardware rendering operations -------------------------------------------

  inline static GAME_ERROR ADDON_HwContextReset(const AddonInstance_Game* instance)
  {
    return instance->toAddon.addonInstance->HwContextReset();
  }

  inline static GAME_ERROR ADDON_HwContextDestroy(const AddonInstance_Game* instance)
  {
    return instance->toAddon.addonInstance->HwContextDestroy();
  }


  // --- Input operations --------------------------------------------------------

  inline static bool ADDON_HasFeature(const AddonInstance_Game* instance,
                                      const char* controller_id,
                                      const char* feature_name)
  {
    return instance->toAddon.addonInstance->HasFeature(controller_id, feature_name);
  }

  inline static game_input_topology* ADDON_GetTopology(const AddonInstance_Game* instance)
  {
    return instance->toAddon.addonInstance->GetTopology();
  }

  inline static void ADDON_FreeTopology(const AddonInstance_Game* instance,
                                        game_input_topology* topology)
  {
    instance->toAddon.addonInstance->FreeTopology(topology);
  }

  inline static void ADDON_SetControllerLayouts(const AddonInstance_Game* instance,
                                                const game_controller_layout* controllers,
                                                unsigned int controller_count)
  {
    if (controllers == nullptr)
      return;

    std::vector<AddonGameControllerLayout> controllerList;
    for (unsigned int i = 0; i < controller_count; ++i)
      controllerList.push_back(controllers[i]);

    instance->toAddon.addonInstance->SetControllerLayouts(controllerList);
  }

  inline static bool ADDON_EnableKeyboard(const AddonInstance_Game* instance,
                                          bool enable,
                                          const char* controller_id)
  {
    return instance->toAddon.addonInstance->EnableKeyboard(enable, controller_id);
  }

  inline static bool ADDON_EnableMouse(const AddonInstance_Game* instance,
                                       bool enable,
                                       const char* controller_id)
  {
    return instance->toAddon.addonInstance->EnableMouse(enable, controller_id);
  }

  inline static bool ADDON_ConnectController(const AddonInstance_Game* instance,
                                             bool connect,
                                             const char* port_address,
                                             const char* controller_id)
  {
    return instance->toAddon.addonInstance->ConnectController(connect, port_address, controller_id);
  }

  inline static bool ADDON_InputEvent(const AddonInstance_Game* instance,
                                      const game_input_event* event)
  {
    return instance->toAddon.addonInstance->InputEvent(*event);
  }


  // --- Serialization operations ------------------------------------------------

  inline static size_t ADDON_SerializeSize(const AddonInstance_Game* instance)
  {
    return instance->toAddon.addonInstance->SerializeSize();
  }

  inline static GAME_ERROR ADDON_Serialize(const AddonInstance_Game* instance,
                                           uint8_t* data,
                                           size_t size)
  {
    return instance->toAddon.addonInstance->Serialize(data, size);
  }

  inline static GAME_ERROR ADDON_Deserialize(const AddonInstance_Game* instance,
                                             const uint8_t* data,
                                             size_t size)
  {
    return instance->toAddon.addonInstance->Deserialize(data, size);
  }


  // --- Cheat operations --------------------------------------------------------

  inline static GAME_ERROR ADDON_CheatReset(const AddonInstance_Game* instance)
  {
    return instance->toAddon.addonInstance->CheatReset();
  }

  inline static GAME_ERROR ADDON_GetMemory(const AddonInstance_Game* instance,
                                           GAME_MEMORY type,
                                           uint8_t** data,
                                           size_t* size)
  {
    return instance->toAddon.addonInstance->GetMemory(type, *data, *size);
  }

  inline static GAME_ERROR ADDON_SetCheat(const AddonInstance_Game* instance,
                                          unsigned int index,
                                          bool enabled,
                                          const char* code)
  {
    return instance->toAddon.addonInstance->SetCheat(index, enabled, code);
  }

  AddonInstance_Game* m_instanceData;
};

} /* namespace addon */
} /* namespace kodi */