Steam.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /******************************************************************************/
  2. struct SteamWorks
  3. {
  4. enum RESULT
  5. {
  6. STEAM_NOT_INITIALIZED , // Steam failed to initialize
  7. STEAM_NOT_SETUP , // 'Steam.webApiKey' was not specified
  8. APP_ID_UNAVAILABLE , // App Steam ID is unavailable
  9. USER_ID_UNAVAILABLE , // User Steam ID is unavailable
  10. WAITING , // result is not yet known as the command was forwarded further, the result will be passed to the 'callback' function (if specified) at a later time
  11. ORDER_REQUEST_FAILED , // order request failed
  12. ORDER_REQUEST_OK , // order request was processed by Steam and it should be displayed on the app screen by "Steam Game Overlay" for user to authorize it
  13. ORDER_USER_CANCELED , // order was canceled by the user
  14. ORDER_FINALIZE_FAILED , // user authorized the order, however its finalization failed
  15. ORDER_FINALIZE_OK , // user authorized the order and Steam finalized it successfully, this means that the order was fully processed and payment was transferred
  16. PURCHASE_STATUS_FAILED , // failed to obtain the purchase status
  17. PURCHASE_STATUS_OK , // purchase status was obtained successfully (this does not mean that the purchase was finalized, only that the status is known, for finalized status please check 'Purchase.finalized' member)
  18. SUBSCRIPTION_STATUS_FAILED, // failed to obtain the subscription status
  19. SUBSCRIPTION_STATUS_OK , // subscription status was obtained successfully (this does not mean that a subscription exists, to check if it exists please investigate the 'subscription' function parameter)
  20. };
  21. enum USER_STATUS
  22. {
  23. STATUS_UNKNOWN, // Steam not connected
  24. STATUS_OFFLINE,
  25. STATUS_ONLINE ,
  26. STATUS_AWAY ,
  27. };
  28. enum FRIEND_STATE_CHANGE_FLAG
  29. {
  30. FRIEND_STATE_CHANGE_Name =0x0001,
  31. FRIEND_STATE_CHANGE_Status =0x0002,
  32. FRIEND_STATE_CHANGE_ComeOnline =0x0004,
  33. FRIEND_STATE_CHANGE_GoneOffline =0x0008,
  34. FRIEND_STATE_CHANGE_GamePlayed =0x0010,
  35. FRIEND_STATE_CHANGE_GameServer =0x0020,
  36. FRIEND_STATE_CHANGE_Avatar =0x0040,
  37. FRIEND_STATE_CHANGE_JoinedSource =0x0080,
  38. FRIEND_STATE_CHANGE_LeftSource =0x0100,
  39. FRIEND_STATE_CHANGE_RelationshipChanged=0x0200,
  40. FRIEND_STATE_CHANGE_NameFirstSet =0x0400,
  41. FRIEND_STATE_CHANGE_FacebookInfo =0x0800,
  42. FRIEND_STATE_CHANGE_Nickname =0x1000,
  43. FRIEND_STATE_CHANGE_SteamLevel =0x2000,
  44. };
  45. enum PERIOD
  46. {
  47. DAY ,
  48. WEEK ,
  49. MONTH,
  50. YEAR ,
  51. };
  52. struct Purchase // purchase status, can be available only in PURCHASE_STATUS_OK
  53. {
  54. Bool finalized; // if purchase was finalized
  55. ULong user_id; // User Steam ID for this purchase
  56. Int item_id, // Item ID for this purchase
  57. cost_in_cents; // cost in cents for this purchase
  58. Str currency, // currency of the purchase
  59. country; // country code of the purchase
  60. DateTime date; // date of the purchase
  61. Purchase();
  62. };
  63. struct Subscription // subscription status, can be available only in SUBSCRIPTION_STATUS_OK
  64. {
  65. Bool active; // if the subscription is active or canceled
  66. Int item_id, // Item ID for this subscription
  67. cost_in_cents, // cost in cents for this subscription
  68. frequency; // frequency of the subscription
  69. PERIOD period; // period of the subscription
  70. Str currency; // currency of the subscription
  71. DateTime created, // date when the subscription was created
  72. last_payment, // date of the last payment
  73. next_payment; // date of the next payment
  74. Bool valid()C; // calculate if this subscription is currently valid (note that canceled subscription is still valid as long as it's not expired yet)
  75. Subscription();
  76. };
  77. static Str StoreLink(C Str &app_id); // return a website link to Steam Store page for the specified App ID, 'app_id' example = "366810"
  78. void (*order_callback)(RESULT result, ULong order_id, C Str &error_message, C Purchase *purchase, C Subscription *subscription); // pointer to a custom function that will be called with processed events of an order, 'result'=message received at the moment, 'purchase'=status of the purchase (can be available only in PURCHASE_STATUS_OK), 'subscription'=status of the subscription (can be available only in SUBSCRIPTION_STATUS_OK or it can be null which means that there's no subscription)
  79. void (*friend_state_changed)(ULong friend_id, UInt flags); // pointer to a custom function that will be called when state of a friend changed, 'friend_id'=friend Steam ID, 'flags'=FRIEND_STATE_CHANGE_FLAG
  80. // get
  81. Bool initialized ( )C {return _initialized;} // if Steam is initialized
  82. UInt appID ( )C; // get app Steam ID
  83. ULong userID ( )C; // get user Steam ID
  84. Str userName ( )C; // get user name
  85. USER_STATUS userStatus ( )C; // get user status
  86. Bool userAvatar (Image &image)C; // get user avatar
  87. CChar8* appLanguage ( )C; // get current app language
  88. CChar8* country ( )C; // get country code in which user is currently located according to Steam
  89. DateTime date ( )C; // get current date time in UTC time zone according to Steam
  90. UInt curTimeS ( )C; // get real time in current moment (seconds since application started, NOT modified by game 'speed', NOT affected by 'smooth' 'skipUpdate' and application pauses)
  91. Bool overlayAvailable ( )C; // get if "Steam Game Overlay" can be displayed to the user if needed (it is required for making any purchases), please note that the overlay could take a few seconds to start, so this function will initially return false while the overlay is loading
  92. Bool overlayAvailableMsgBox( )C; // this method works like 'overlayAvailable', however on failure it additionally displays a message box, instructing the user to enable the Overlay through Steam Settings
  93. Bool drmExit ( )C; // perform a DRM (Digital Rights Management) check if the app should be closed. Calling this method is optional. If called then this method should be used in 'InitPre' function in the following way: "if(Steam.drmExit())return;" This method performs a check if the application was started by Steam Client. If it was, then false is returned and the app can continue to operate. If it was not started by Steam Client, then: APP_EXIT_IMMEDIATELY is added to the 'App.flag' (so that the App will exit after 'InitPre'), true is returned so you can return from 'InitPre' immediately, Steam Client will restart the app. If you're using "Steam DRM Wrapper" described in https://partner.steamgames.com/documentation/drm then you don't need this check.
  94. // friends
  95. Bool getFriends(MemPtr<ULong> friend_ids )C; // get list of friend ID's, false on fail
  96. Str userName ( ULong user_id )C; // get user name , "" on fail
  97. USER_STATUS userStatus( ULong user_id )C; // get user status , STATUS_UNKNOWN on fail
  98. Bool userAvatar( ULong user_id, Image &image)C; // get user avatar , false on fail
  99. // operations
  100. SteamWorks& webApiKey(C Str8 &web_api_key); // set Steam WEB API Key, you can create/obtain it on "https://partner.steamgames.com/pub/groups/" website
  101. // making purchases requires that the "Steam Game Overlay" is available, which you can check using 'overlayAvailable' method
  102. RESULT purchase (ULong order_id, Int item_id, C Str &item_name, Int cost_in_cents, C Str8 &currency="USD"); // purchase an item, 'order_id'=unique order ID (making multiple calls with the same OrderID will fail), 'item_id'=ID of the item to purchase, 'item_name'=name of the item to purchase, 'cost_in_cents'=cost in cents (for example 99=0.99$, 150=1.50$), 'currency'=currency of the purchase
  103. RESULT subscribe (ULong order_id, Int item_id, C Str &item_name, Int cost_in_cents, PERIOD period, Int frequency, C Str8 &currency="USD"); // purchase an item, 'order_id'=unique order ID (making multiple calls with the same OrderID will fail), 'item_id'=ID of the item to purchase, 'item_name'=name of the item to purchase, 'cost_in_cents'=cost in cents (for example 99=0.99$, 150=1.50$), 'currency'=currency of the subscription, 'period,frequency'=how often the subscription should recur (for example, for every 1 month set "MONTH, 2", for every 2 weeks set "WEEK, 2")
  104. RESULT purchaseState (ULong order_id); // get status of a purchase, this method will contact Steam and return the result through the 'callback' function
  105. RESULT subscriptionState(); // get status of user subscriptions, this method will contact Steam and return the result through the 'callback' function
  106. // cloud IO, these methods require setting up Cloud settings on your App Steam Page - https://partner.steamgames.com/apps/cloud/XXX
  107. Long cloudAvailableSize()C; // get number of available bytes for cloud storage, 0 on fail
  108. Long cloudTotalSize ()C; // get number of total bytes for cloud storage, 0 on fail
  109. Bool cloudDel (C Str &file_name); // delete 'file_name', false on fail
  110. Bool cloudExists (C Str &file_name); // check if 'file_name' exists
  111. Long cloudSize (C Str &file_name); // get size of 'file_name', 0 on fail
  112. DateTime cloudTimeUTC(C Str &file_name); // get modification time of 'file_name'
  113. Bool cloudSave(C Str &file_name, File &f, Cipher *cipher=null); // save data from 'file' to 'file_name' cloud file, false on fail, only data from current 'f' file position to the end of the file is saved
  114. Bool cloudLoad(C Str &file_name, File &f, Bool memory, Cipher *cipher=null); // load file from 'file_name' cloud file to 'file', false on fail, 'f' should be already opened for writing if 'memory' is set to false, if 'memory' is set to true then 'f' will be first reinitialized with 'writeMemFixed' before loading, which means that load result will not be stored into original 'f' target, but instead into a dynamically allocated memory
  115. Bool cloudSave(C Str &file_name, CPtr data, Int size); // save data from 'data' to 'file_name' cloud file, false on fail
  116. Bool cloudLoad(C Str &file_name, Ptr data, Int size); // load data from 'file_name' cloud file to 'data', false on fail
  117. Int cloudFiles( )C; // get number of files that are currently stored in the cloud
  118. Bool cloudFile (Int i, Str &name, Long &size)C; // get i-th cloud file name and size, false on fail
  119. // manage
  120. Bool init(); // manually initialize and return if initializion was ok, you don't need to call this as it is automatically called in the constructor
  121. void shut(); // manually shutdown Steam , you don't need to call this as it is automatically called in the destructor
  122. #if !EE_PRIVATE
  123. private:
  124. #endif
  125. struct Operation : Download
  126. {
  127. UInt type;
  128. ULong order_id;
  129. };
  130. Bool _initialized;
  131. UInt _start_time_s;
  132. Str8 _web_api_key;
  133. Memx<Operation> _operations;
  134. #if EE_PRIVATE
  135. void update();
  136. #endif
  137. SteamWorks(); // automatically calls 'init'
  138. ~SteamWorks(); // automatically calls 'shut'
  139. }extern
  140. Steam;
  141. /******************************************************************************/