forked from GodotSteam/GodotSteam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
godotsteam.cpp
13548 lines (12408 loc) · 599 KB
/
godotsteam.cpp
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
/////////////////////////////////////////////////
///// SILENCE STEAMWORKS WARNINGS
/////////////////////////////////////////////////
//
// Turn off MSVC-only warning about strcpy
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS 1
#pragma warning(disable : 4996)
#pragma warning(disable : 4828)
#endif
/////////////////////////////////////////////////
///// HEADER INCLUDES
/////////////////////////////////////////////////
//
// Include GodotSteam header
#include "godotsteam.h"
#include "godotsteam_constants.h"
// Include some Godot headers
#include "core/io/ip.h"
#include "core/io/ip_address.h"
// Include some system headers
#include "fstream"
#include "vector"
/////////////////////////////////////////////////
///// STEAM SINGLETON? STEAM SINGLETON
/////////////////////////////////////////////////
//
Steam *Steam::singleton = NULL;
/////////////////////////////////////////////////
///// STEAM OBJECT WITH CALLBACKS
/////////////////////////////////////////////////
//
Steam::Steam() :
// Apps callbacks ////////////////////////////
callbackDLCInstalled(this, &Steam::dlc_installed),
callbackFileDetailsResult(this, &Steam::file_details_result),
callbackNewLaunchURLParameters(this, &Steam::new_launch_url_parameters),
callbackTimedTrialStatus(this, &Steam::timed_trial_status),
// Friends callbacks ////////////////////////
callbackAvatarLoaded(this, &Steam::avatar_loaded),
callbackAvatarImageLoaded(this, &Steam::avatar_image_loaded),
callbackClanActivityDownloaded(this, &Steam::clan_activity_downloaded),
callbackFriendRichPresenceUpdate(this, &Steam::friend_rich_presence_update),
callbackConnectedChatJoin(this, &Steam::connected_chat_join),
callbackConnectedChatLeave(this, &Steam::connected_chat_leave),
callbackConnectedClanChatMessage(this, &Steam::connected_clan_chat_message),
callbackConnectedFriendChatMessage(this, &Steam::connected_friend_chat_message),
callbackJoinRequested(this, &Steam::join_requested),
callbackOverlayToggled(this, &Steam::overlay_toggled),
callbackJoinGameRequested(this, &Steam::join_game_requested),
callbackChangeServerRequested(this, &Steam::change_server_requested),
callbackJoinClanChatComplete(this, &Steam::join_clan_chat_complete),
callbackPersonaStateChange(this, &Steam::persona_state_change),
callbackNameChanged(this, &Steam::name_changed),
callbackOverlayBrowserProtocol(this, &Steam::overlay_browser_protocol),
callbackUnreadChatMessagesChanged(this, &Steam::unread_chat_messages_changed),
callbackEquippedProfileItemsChanged(this, &Steam::equipped_profile_items_changed),
// Game Search callbacks ////////////////////
callbackSearchForGameProgress(this, &Steam::search_for_game_progress),
callbackSearchForGameResult(this, &Steam::search_for_game_result),
callbackRequestPlayersForGameProgress(this, &Steam::request_players_for_game_progress),
callbackRequestPlayersForGameResult(this, &Steam::request_players_for_game_result),
callbackRequestPlayersForGameFinalResult(this, &Steam::request_players_for_game_final_result),
callbackSubmitPlayerResult(this, &Steam::submit_player_result),
callbackEndGameResult(this, &Steam::end_game_result),
// HTML Surface callbacks ///////////////////
callbackHTMLCanGoBackandforward(this, &Steam::html_can_go_backandforward),
callbackHTMLChangedTitle(this, &Steam::html_changed_title),
callbackHTMLCloseBrowser(this, &Steam::html_close_browser),
callbackHTMLFileOpenDialog(this, &Steam::html_file_open_dialog),
callbackHTMLFinishedRequest(this, &Steam::html_finished_request),
callbackHTMLHideTooltip(this, &Steam::html_hide_tooltip),
callbackHTMLHorizontalScroll(this, &Steam::html_horizontal_scroll),
callbackHTMLJSAlert(this, &Steam::html_js_alert),
callbackHTMLJSConfirm(this, &Steam::html_js_confirm),
callbackHTMLLinkAtPosition(this, &Steam::html_link_at_position),
callbackHTMLNeedsPaint(this, &Steam::html_needs_paint),
callbackHTMLNewWindow(this, &Steam::html_new_window),
callbackHTMLOpenLinkInNewTab(this, &Steam::html_open_link_in_new_tab),
callbackHTMLSearchResults(this, &Steam::html_search_results),
callbackHTMLSetCursor(this, &Steam::html_set_cursor),
callbackHTMLShowTooltip(this, &Steam::html_show_tooltip),
callbackHTMLStartRequest(this, &Steam::html_start_request),
callbackHTMLStatusText(this, &Steam::html_status_text),
callbackHTMLUpdateTooltip(this, &Steam::html_update_tooltip),
callbackHTMLURLChanged(this, &Steam::html_url_changed),
callbackHTMLVerticalScroll(this, &Steam::html_vertical_scroll),
// HTTP callbacks ///////////////////////////
callbackHTTPRequestCompleted(this, &Steam::http_request_completed),
callbackHTTPRequestDataReceived(this, &Steam::http_request_data_received),
callbackHTTPRequestHeadersReceived(this, &Steam::http_request_headers_received),
// Input callbacks //////////////////////////
callbackInputDeviceConnected(this, &Steam::input_device_connected),
callbackInputDeviceDisconnected(this, &Steam::input_device_disconnected),
callbackInputConfigurationLoaded(this, &Steam::input_configuration_loaded),
callbackInputGamePadSlotChange(this, &Steam::input_gamepad_slot_change),
// Inventory callbacks //////////////////////
callbackInventoryDefinitionUpdate(this, &Steam::inventory_definition_update),
callbackInventoryFullUpdate(this, &Steam::inventory_full_update),
callbackInventoryResultReady(this, &Steam::inventory_result_ready),
// Matchmaking callbacks ////////////////////
callbackFavoritesListAccountsUpdated(this, &Steam::favorites_list_accounts_updated),
callbackFavoritesListChanged(this, &Steam::favorites_list_changed),
callbackLobbyMessage(this, &Steam::lobby_message),
callbackLobbyChatUpdate(this, &Steam::lobby_chat_update),
callbackLobbyDataUpdate(this, &Steam::lobby_data_update),
callbackLobbyJoined(this, &Steam::lobby_joined),
callbackLobbyGameCreated(this, &Steam::lobby_game_created),
callbackLobbyInvite(this, &Steam::lobby_invite),
callbackLobbyKicked(this, &Steam::lobby_kicked),
// Music callbacks //////////////////////////
callbackMusicPlaybackStatusHasChanged(this, &Steam::music_playback_status_has_changed),
callbackMusicVolumeHasChanged(this, &Steam::music_volume_has_changed),
// Music Remote callbacks ///////////////////
callbackMusicPlayerRemoteToFront(this, &Steam::music_player_remote_to_front),
callbackMusicPlayerRemoteWillActivate(this, &Steam::music_player_remote_will_activate),
callbackMusicPlayerRemoteWillDeactivate(this, &Steam::music_player_remote_will_deactivate),
callbackMusicPlayerSelectsPlaylistEntry(this, &Steam::music_player_selects_playlist_entry),
callbackMusicPlayerSelectsQueueEntry(this, &Steam::music_player_selects_queue_entry),
callbackMusicPlayerWantsLooped(this, &Steam::music_player_wants_looped),
callbackMusicPlayerWantsPause(this, &Steam::music_player_wants_pause),
callbackMusicPlayerWantsPlayingRepeatStatus(this, &Steam::music_player_wants_playing_repeat_status),
callbackMusicPlayerWantsPlayNext(this, &Steam::music_player_wants_play_next),
callbackMusicPlayerWantsPlayPrevious(this, &Steam::music_player_wants_play_previous),
callbackMusicPlayerWantsPlay(this, &Steam::music_player_wants_play),
callbackMusicPlayerWantsShuffled(this, &Steam::music_player_wants_shuffled),
callbackMusicPlayerWantsVolume(this, &Steam::music_player_wants_volume),
callbackMusicPlayerWillQuit(this, &Steam::music_player_will_quit),
// Networking callbacks /////////////////////
callbackP2PSessionConnectFail(this, &Steam::p2p_session_connect_fail),
callbackP2PSessionRequest(this, &Steam::p2p_session_request),
// Networking Messages callbacks ////////////
callbackNetworkMessagesSessionRequest(this, &Steam::network_messages_session_request),
callbackNetworkMessagesSessionFailed(this, &Steam::network_messages_session_failed),
// Networking Sockets callbacks /////////////
callbackNetworkConnectionStatusChanged(this, &Steam::network_connection_status_changed),
callbackNetworkAuthenticationStatus(this, &Steam::network_authentication_status),
callbackNetworkingFakeIPResult(this, &Steam::fake_ip_result),
// Networking Utils callbacks ///////////////
callbackRelayNetworkStatus(this, &Steam::relay_network_status),
// Parental Settings callbacks //////////////
callbackParentlSettingChanged(this, &Steam::parental_setting_changed),
// Parties callbacks ////////////////////////
callbackReserveNotification(this, &Steam::reservation_notification),
callbackAvailableBeaconLocationsUpdated(this, &Steam::available_beacon_locations_updated),
callbackActiveBeaconsUpdated(this, &Steam::active_beacons_updated),
// Remote Play callbacks ////////////////////
callbackRemotePlaySessionConnected(this, &Steam::remote_play_session_connected),
callbackRemotePlaySessionDisconnected(this, &Steam::remote_play_session_disconnected),
// Remote Storage callbacks /////////////////
callbackLocalFileChanged(this, &Steam::local_file_changed),
// Screenshot callbacks /////////////////////
callbackScreenshotReady(this, &Steam::screenshot_ready),
callbackScreenshotRequested(this, &Steam::screenshot_requested),
// UGC callbacks ////////////////////////////
callbackItemDownloaded(this, &Steam::item_downloaded),
callbackItemInstalled(this, &Steam::item_installed),
callbackUserSubscribedItemsListChanged(this, &Steam::user_subscribed_items_list_changed),
// User callbacks ///////////////////////////
callbackClientGameServerDeny(this, &Steam::client_game_server_deny),
callbackGameWebCallback(this, &Steam::game_web_callback),
callbackGetAuthSessionTicketResponse(this, &Steam::get_auth_session_ticket_response),
callbackGetTicketForWebApiResponse(this, &Steam::get_ticket_for_web_api),
callbackIPCFailure(this, &Steam::ipc_failure),
callbackLicensesUpdated(this, &Steam::licenses_updated),
callbackMicrotransactionAuthResponse(this, &Steam::microtransaction_auth_response),
callbackSteamServerConnected(this, &Steam::steam_server_connected),
callbackSteamServerDisconnected(this, &Steam::steam_server_disconnected),
callbackValidateAuthTicketResponse(this, &Steam::validate_auth_ticket_response),
// User stat callbacks //////////////////////
callbackUserAchievementStored(this, &Steam::user_achievement_stored),
callbackCurrentStatsReceived(this, &Steam::current_stats_received),
callbackUserStatsStored(this, &Steam::user_stats_stored),
callbackUserStatsUnloaded(this, &Steam::user_stats_unloaded),
// Utility callbacks ////////////////////////
callbackGamepadTextInputDismissed(this, &Steam::gamepad_text_input_dismissed),
callbackIPCountry(this, &Steam::ip_country),
callbackLowPower(this, &Steam::low_power),
callbackSteamAPICallCompleted(this, &Steam::steam_api_call_completed),
callbackSteamShutdown(this, &Steam::steam_shutdown),
callbackAppResumingFromSuspend(this, &Steam::app_resuming_from_suspend),
callbackFloatingGamepadTextInputDismissed(this, &Steam::floating_gamepad_text_input_dismissed),
callbackFilterTextDictionaryChanged(this, &Steam::filter_text_dictionary_changed),
// Video callbacks //////////////////////////
callbackGetOPFSettingsResult(this, &Steam::get_opf_settings_result),
callbackGetVideoResult(this, &Steam::get_video_result)
{
is_init_success = false;
singleton = this;
were_callbacks_embedded = false;
}
/////////////////////////////////////////////////
///// INTERNAL FUNCTIONS
/////////////////////////////////////////////////
//
// Get the Steam singleton, obviously
Steam *Steam::get_singleton() {
return singleton;
}
// Creating a Steam ID for internal use
CSteamID Steam::createSteamID(uint64_t steam_id, AccountType account_type) {
CSteamID converted_steam_id;
if (account_type < 0 || account_type >= AccountType(k_EAccountTypeMax)) {
account_type = ACCOUNT_TYPE_INDIVIDUAL;
}
converted_steam_id.Set(steam_id, k_EUniversePublic, EAccountType(account_type));
return converted_steam_id;
}
/////////////////////////////////////////////////
///// MAIN FUNCTIONS
/////////////////////////////////////////////////
//
// Returns true/false if Steam is running.
bool Steam::isSteamRunning(void) {
return SteamAPI_IsSteamRunning();
}
// Checks if your executable was launched through Steam and relaunches it through Steam if it wasn't.
bool Steam::restartAppIfNecessary(uint32 app_id) {
return SteamAPI_RestartAppIfNecessary((AppId_t)app_id);
}
// Initialize the SDK, without worrying about the cause of failure.
Dictionary Steam::steamInit(bool retrieve_stats, uint32_t app_id, bool embed_callbacks) {
// Set the app ID
if (app_id != 0){
OS::get_singleton()->set_environment("SteamAppId", itos(app_id));
OS::get_singleton()->set_environment("SteamGameId", itos(app_id));
}
// Start the initialization process
Dictionary initialize;
// Attempt to initialize Steamworks
is_init_success = SteamAPI_Init();
// Set the default status response
int status = RESULT_FAIL;
String verbal = "Steamworks failed to initialize.";
// Steamworks initialized with no problems
if(is_init_success){
status = RESULT_OK;
verbal = "Steamworks active.";
current_app_id = app_id;
// Get the current stats, if set
if(SteamUserStats() != NULL && retrieve_stats){
requestCurrentStats();
}
// Attach the callbacks, if set
if (embed_callbacks) {
were_callbacks_embedded = true;
auto callbacks = callable_mp(Steam::singleton, &Steam::run_callbacks);
SceneTree::get_singleton()->connect("process_frame", callbacks);
SceneTree::get_singleton()->connect("physics_frame", callbacks);
}
}
else{
// The Steam client is not running
if(!isSteamRunning()){
status = RESULT_SERVICE_UNAVAILABLE;
verbal = "Steam not running.";
}
else if(SteamUser() == NULL){
status = RESULT_UNEXPECTED_ERROR;
verbal = "Invalid app ID or app not installed.";
}
}
initialize["status"] = status;
initialize["verbal"] = verbal;
return initialize;
}
// Initialize the Steamworks SDK. On success STEAM_API_INIT_RESULT_OK is returned.
// Otherwise, if error_message is non-NULL, it will receive a non-localized message that explains the reason for the failure.
Dictionary Steam::steamInitEx(bool retrieve_stats, uint32_t app_id, bool embed_callbacks){
// Set the app ID
if (app_id != 0) {
OS::get_singleton()->set_environment("SteamAppId", itos(app_id));
OS::get_singleton()->set_environment("SteamGameId", itos(app_id));
}
// Start the initialization process
Dictionary initialize;
char error_message[STEAM_MAX_ERROR_MESSAGE];
ESteamAPIInitResult initialize_result;
initialize_result = SteamAPI_InitEx(&error_message);
if (initialize_result == (ESteamAPIInitResult)STEAM_API_INIT_RESULT_OK) {
is_init_success = true;
current_app_id = app_id;
// Get the current stats, if set
if (SteamUserStats() != NULL && retrieve_stats) {
requestCurrentStats();
}
// Attach the callbacks, if set
if (embed_callbacks) {
were_callbacks_embedded = true;
auto callbacks = callable_mp(Steam::singleton, &Steam::run_callbacks);
SceneTree::get_singleton()->connect("process_frame", callbacks);
SceneTree::get_singleton()->connect("physics_frame", callbacks);
}
}
initialize["status"] = initialize_result;
initialize["verbal"] = error_message;
return initialize;
}
// Shuts down the Steamworks API, releases pointers and frees memory.
void Steam::steamShutdown() {
SteamAPI_Shutdown();
// If callbacks were connected internally
if(were_callbacks_embedded){
were_callbacks_embedded = false;
auto callbacks = callable_mp(Steam::singleton, &Steam::run_callbacks);
SceneTree::get_singleton()->disconnect("process_frame", callbacks);
SceneTree::get_singleton()->disconnect("physics_frame", callbacks);
}
}
/////////////////////////////////////////////////
///// APPS
/////////////////////////////////////////////////
//
// Returns metadata for a DLC by index.
Array Steam::getDLCDataByIndex() {
if (SteamApps() == NULL) {
return Array();
}
int32 count = SteamApps()->GetDLCCount();
Array dlcData;
for (int i = 0; i < count; i++) {
AppId_t app_id = 0;
bool available = false;
char name[STEAM_BUFFER_SIZE];
bool success = SteamApps()->BGetDLCDataByIndex(i, &app_id, &available, name, STEAM_BUFFER_SIZE);
if (success) {
Dictionary dlc;
dlc["id"] = app_id;
dlc["available"] = available;
dlc["name"] = name;
dlcData.append(dlc);
}
}
return dlcData;
}
// Check if given application/game is installed, not necessarily owned.
bool Steam::isAppInstalled(uint32_t app_id) {
if (SteamApps() == NULL) {
return false;
}
return SteamApps()->BIsAppInstalled((AppId_t)app_id);
}
// Checks whether the current App ID is for Cyber Cafes.
bool Steam::isCybercafe() {
if (SteamApps() == NULL) {
return false;
}
return SteamApps()->BIsCybercafe();
}
// Checks if the user owns a specific DLC and if the DLC is installed
bool Steam::isDLCInstalled(uint32_t dlc_id) {
if (SteamApps() == NULL) {
return false;
}
return SteamApps()->BIsDlcInstalled((AppId_t)dlc_id);
}
// Checks if the license owned by the user provides low violence depots.
bool Steam::isLowViolence() {
if (SteamApps() == NULL) {
return false;
}
return SteamApps()->BIsLowViolence();
}
// Checks if the active user is subscribed to the current App ID.
bool Steam::isSubscribed() {
if (SteamApps() == NULL) {
return false;
}
return SteamApps()->BIsSubscribed();
}
// Checks if the active user is subscribed to a specified AppId.
bool Steam::isSubscribedApp(uint32_t app_id) {
if (SteamApps() == NULL) {
return false;
}
return SteamApps()->BIsSubscribedApp((AppId_t)app_id);
}
// Checks if the active user is accessing the current app_id via a temporary Family Shared license owned by another user.
// If you need to determine the steam_id of the permanent owner of the license, use getAppOwner.
bool Steam::isSubscribedFromFamilySharing() {
if (SteamApps() == NULL) {
return false;
}
return SteamApps()->BIsSubscribedFromFamilySharing();
}
// Checks if the user is subscribed to the current app through a free weekend.
// This function will return false for users who have a retail or other type of license.
// Suggested you contact Valve on how to package and secure your free weekend properly.
bool Steam::isSubscribedFromFreeWeekend() {
if (SteamApps() == NULL) {
return false;
}
return SteamApps()->BIsSubscribedFromFreeWeekend();
}
// Check if game is a timed trial with limited playtime.
Dictionary Steam::isTimedTrial() {
Dictionary trial;
if (SteamApps() != NULL) {
uint32 allowed = 0;
uint32 played = 0;
if (SteamApps()->BIsTimedTrial(&allowed, &played)) {
trial["seconds_allowed"] = allowed;
trial["seconds_played"] = played;
}
}
return trial;
}
// Checks if the user has a VAC ban on their account.
bool Steam::isVACBanned() {
if (SteamApps() == NULL) {
return false;
}
return SteamApps()->BIsVACBanned();
}
// Return the build ID for this app; will change based on backend updates.
int Steam::getAppBuildId() {
if (SteamApps() == NULL) {
return 0;
}
return SteamApps()->GetAppBuildId();
}
// Gets the install folder for a specific AppID.
Dictionary Steam::getAppInstallDir(uint32_t app_id) {
Dictionary app_install;
if (SteamApps() != NULL) {
char buffer[STEAM_BUFFER_SIZE];
uint32 install_size = SteamApps()->GetAppInstallDir((AppId_t)app_id, buffer, STEAM_BUFFER_SIZE);
String install_directory = buffer;
// If we get no install directory, mention a possible cause
if (install_directory.is_empty()) {
install_directory = "Possible wrong app ID or missing depot";
}
app_install["directory"] = install_directory;
app_install["install_size"] = install_size;
}
return app_install;
}
// Gets the Steam ID of the original owner of the current app. If it's different from the current user then it is borrowed.
uint64_t Steam::getAppOwner() {
if (SteamApps() == NULL) {
return 0;
}
CSteamID converted_steam_id = SteamApps()->GetAppOwner();
return converted_steam_id.ConvertToUint64();
}
// Gets a comma separated list of the languages the current app supports.
String Steam::getAvailableGameLanguages() {
if (SteamApps() == NULL) {
return "None";
}
return SteamApps()->GetAvailableGameLanguages();
}
// Checks if the user is running from a beta branch, and gets the name of the branch if they are.
String Steam::getCurrentBetaName() {
String beta_name = "";
if (SteamApps() != NULL) {
char name_string[STEAM_LARGE_BUFFER_SIZE];
if (SteamApps()->GetCurrentBetaName(name_string, STEAM_LARGE_BUFFER_SIZE)) {
beta_name = String(name_string);
}
}
return beta_name;
}
// Gets the current language that the user has set.
String Steam::getCurrentGameLanguage() {
if (SteamApps() == NULL) {
return "None";
}
return SteamApps()->GetCurrentGameLanguage();
}
// Get the number of DLC the user owns for a parent application/game.
int Steam::getDLCCount() {
if (SteamApps() == NULL) {
return false;
}
return SteamApps()->GetDLCCount();
}
// Gets the download progress for optional DLC.
Dictionary Steam::getDLCDownloadProgress(uint32_t dlc_id) {
Dictionary progress;
if (SteamApps() == NULL) {
progress["ret"] = false;
} else {
uint64 downloaded = 0;
uint64 total = 0;
// Get the progress
progress["ret"] = SteamApps()->GetDlcDownloadProgress((AppId_t)dlc_id, &downloaded, &total);
if (progress["ret"]) {
progress["downloaded"] = uint64_t(downloaded);
progress["total"] = uint64_t(total);
}
}
return progress;
}
// Gets the time of purchase of the specified app in Unix epoch format (time since Jan 1st, 1970).
uint32_t Steam::getEarliestPurchaseUnixTime(uint32_t app_id) {
if (SteamApps() == NULL) {
return 0;
}
return SteamApps()->GetEarliestPurchaseUnixTime((AppId_t)app_id);
}
// Asynchronously retrieves metadata details about a specific file in the depot manifest.
void Steam::getFileDetails(const String &filename) {
if (SteamApps() != NULL) {
SteamApps()->GetFileDetails(filename.utf8().get_data());
}
}
// Gets a list of all installed depots for a given App ID.
// @param app_id App ID to check.
// @return Array of the installed depots, returned in mount order.
Array Steam::getInstalledDepots(uint32_t app_id) {
if (SteamApps() == NULL) {
return Array();
}
Array installed_depots;
DepotId_t *depots = new DepotId_t[32];
uint32 installed = SteamApps()->GetInstalledDepots((AppId_t)app_id, depots, 32);
for (uint32 i = 0; i < installed; i++) {
installed_depots.append(depots[i]);
}
delete[] depots;
return installed_depots;
}
// Gets the command line if the game was launched via Steam URL, e.g. steam://run/<appid>//<command line>/. This method is preferable to launching with a command line via the operating system, which can be a security risk. In order for rich presence joins to go through this and not be placed on the OS command line, you must enable "Use launch command line" from the Installation > General page on your app.
String Steam::getLaunchCommandLine() {
if (SteamApps() == NULL) {
return "";
}
char commands[STEAM_BUFFER_SIZE];
SteamApps()->GetLaunchCommandLine(commands, STEAM_BUFFER_SIZE);
String command_line;
command_line += commands;
return command_line;
}
// Gets the associated launch parameter if the game is run via steam://run/<appid>/?param1=value1;param2=value2;param3=value3 etc.
String Steam::getLaunchQueryParam(const String &key) {
if (SteamApps() == NULL) {
return "";
}
return SteamApps()->GetLaunchQueryParam(key.utf8().get_data());
}
// Allows you to install an optional DLC.
void Steam::installDLC(uint32_t dlc_id) {
if (SteamApps() != NULL) {
SteamApps()->InstallDLC((AppId_t)dlc_id);
}
}
// Allows you to force verify game content on next launch.
bool Steam::markContentCorrupt(bool missing_files_only) {
if (SteamApps() == NULL) {
return false;
}
return SteamApps()->MarkContentCorrupt(missing_files_only);
}
// Set current DLC AppID being played (or 0 if none). Allows Steam to track usage of major DLC extensions.
bool Steam::setDLCContext(uint32_t app_id) {
if (SteamApps() == NULL) {
return false;
}
return SteamApps()->SetDlcContext((AppId_t)app_id);
}
// Allows you to uninstall an optional DLC.
void Steam::uninstallDLC(uint32_t dlc_id) {
if (SteamApps() != NULL) {
SteamApps()->UninstallDLC((AppId_t)dlc_id);
}
}
/////////////////////////////////////////////////
///// FRIENDS
/////////////////////////////////////////////////
//
// Activates the overlay with optional dialog to open the following: "Friends", "Community", "Players", "Settings", "OfficialGameGroup", "Stats", "Achievements", "LobbyInvite".
void Steam::activateGameOverlay(const String &url) {
if (SteamFriends() != NULL) {
SteamFriends()->ActivateGameOverlay(url.utf8().get_data());
}
}
// Activates game overlay to open the invite dialog. Invitations will be sent for the provided lobby.
void Steam::activateGameOverlayInviteDialog(uint64_t steam_id) {
if (SteamFriends() != NULL) {
CSteamID user_id = (uint64)steam_id;
SteamFriends()->ActivateGameOverlayInviteDialog(user_id);
}
}
// Activates the game overlay to open an invite dialog that will send the provided Rich Presence connect string to selected friends.
void Steam::activateGameOverlayInviteDialogConnectString(const String &connect_string) {
if (SteamFriends() != NULL) {
SteamFriends()->ActivateGameOverlayInviteDialogConnectString(connect_string.utf8().get_data());
}
}
// Activates the overlay with the application/game Steam store page.
void Steam::activateGameOverlayToStore(uint32_t app_id) {
if (SteamFriends() != NULL) {
SteamFriends()->ActivateGameOverlayToStore(AppId_t(app_id), EOverlayToStoreFlag(0));
}
}
// Activates the overlay to the following: "steamid", "chat", "jointrade", "stats", "achievements", "friendadd", "friendremove", "friendrequestaccept", "friendrequestignore".
void Steam::activateGameOverlayToUser(const String &url, uint64_t steam_id) {
if (SteamFriends() != NULL) {
CSteamID user_id = (uint64)steam_id;
SteamFriends()->ActivateGameOverlayToUser(url.utf8().get_data(), user_id);
}
}
// Activates the overlay with specified web address.
void Steam::activateGameOverlayToWebPage(const String &url) {
if (SteamFriends() != NULL) {
SteamFriends()->ActivateGameOverlayToWebPage(url.utf8().get_data());
}
}
// Clear the game information in Steam; used in 'View Game Info'.
void Steam::clearRichPresence() {
if (SteamFriends() != NULL) {
SteamFriends()->ClearRichPresence();
}
}
// Closes the specified Steam group chat room in the Steam UI.
bool Steam::closeClanChatWindowInSteam(uint64_t chat_id) {
if (SteamFriends() == NULL) {
return false;
}
CSteamID chat = (uint64)chat_id;
return SteamFriends()->CloseClanChatWindowInSteam(chat);
}
// For clans a user is a member of, they will have reasonably up-to-date information, but for others you'll have to download the info to have the latest.
void Steam::downloadClanActivityCounts(uint64_t clan_id, int clans_to_request) {
if (SteamFriends() != NULL) {
clan_activity = (uint64)clan_id;
SteamFriends()->DownloadClanActivityCounts(&clan_activity, clans_to_request);
}
}
// Gets the list of users that the current user is following.
void Steam::enumerateFollowingList(uint32 start_index) {
if (SteamFriends() != NULL) {
SteamAPICall_t api_call = SteamFriends()->EnumerateFollowingList(start_index);
callResultEnumerateFollowingList.Set(api_call, this, &Steam::enumerate_following_list);
}
}
// Gets the Steam ID at the given index in a Steam group chat.
uint64_t Steam::getChatMemberByIndex(uint64_t clan_id, int user) {
if (SteamFriends() == NULL) {
return 0;
}
clan_activity = (uint64)clan_id;
CSteamID chat_id = SteamFriends()->GetChatMemberByIndex(clan_activity, user);
return chat_id.ConvertToUint64();
}
// Gets the most recent information we have about what the users in a Steam Group are doing.
Dictionary Steam::getClanActivityCounts(uint64_t clan_id) {
Dictionary activity;
if (SteamFriends() == NULL) {
return activity;
}
clan_activity = (uint64)clan_id;
int online = 0;
int ingame = 0;
int chatting = 0;
bool success = SteamFriends()->GetClanActivityCounts(clan_activity, &online, &ingame, &chatting);
// Add these to the dictionary if successful
if (success) {
activity["clan"] = clan_id;
activity["online"] = online;
activity["ingame"] = ingame;
activity["chatting"] = chatting;
}
return activity;
}
// Gets the Steam group's Steam ID at the given index.
uint64_t Steam::getClanByIndex(int clan) {
if (SteamFriends() == NULL) {
return 0;
}
return SteamFriends()->GetClanByIndex(clan).ConvertToUint64();
}
// Get the number of users in a Steam group chat.
int Steam::getClanChatMemberCount(uint64_t clan_id) {
if (SteamFriends() == NULL) {
return 0;
}
clan_activity = (uint64)clan_id;
return SteamFriends()->GetClanChatMemberCount(clan_activity);
}
// Gets the data from a Steam group chat room message. This should only ever be called in response to a GameConnectedClanChatMsg_t callback.
Dictionary Steam::getClanChatMessage(uint64_t chat_id, int message) {
Dictionary chat_message;
if (SteamFriends() == NULL) {
return chat_message;
}
CSteamID chat = (uint64)chat_id;
char text[STEAM_LARGE_BUFFER_SIZE];
EChatEntryType type = k_EChatEntryTypeInvalid;
CSteamID user_id;
chat_message["ret"] = SteamFriends()->GetClanChatMessage(chat, message, text, STEAM_LARGE_BUFFER_SIZE, &type, &user_id);
chat_message["text"] = String(text);
chat_message["type"] = type;
uint64_t user = user_id.ConvertToUint64();
chat_message["chatter"] = user;
return chat_message;
}
// Gets the number of Steam groups that the current user is a member of. This is used for iteration, after calling this then GetClanByIndex can be used to get the Steam ID of each Steam group.
int Steam::getClanCount() {
if (SteamFriends() == NULL) {
return 0;
}
return SteamFriends()->GetClanCount();
}
// Gets the display name for the specified Steam group; if the local client knows about it.
String Steam::getClanName(uint64_t clan_id) {
if (SteamFriends() == NULL) {
return "";
}
clan_activity = (uint64)clan_id;
return String::utf8(SteamFriends()->GetClanName(clan_activity));
}
// Returns the steam_id of a clan officer, by index, of range [0,GetClanOfficerCount).
uint64_t Steam::getClanOfficerByIndex(uint64_t clan_id, int officer) {
if (SteamFriends() == NULL) {
return 0;
}
clan_activity = (uint64)clan_id;
CSteamID officer_id = SteamFriends()->GetClanOfficerByIndex(clan_activity, officer);
return officer_id.ConvertToUint64();
}
// Returns the number of officers in a clan (including the owner).
int Steam::getClanOfficerCount(uint64_t clan_id) {
if (SteamFriends() == NULL) {
return 0;
}
clan_activity = (uint64)clan_id;
return SteamFriends()->GetClanOfficerCount(clan_activity);
}
// Returns the steam_id of the clan owner.
uint64_t Steam::getClanOwner(uint64_t clan_id) {
if (SteamFriends() == NULL) {
return 0;
}
clan_activity = (uint64)clan_id;
CSteamID owner_id = SteamFriends()->GetClanOwner(clan_activity);
return owner_id.ConvertToUint64();
}
// Gets the unique tag (abbreviation) for the specified Steam group; If the local client knows about it. The Steam group abbreviation is a unique way for people to identify the group and is limited to 12 characters. In some games this will appear next to the name of group members.
String Steam::getClanTag(uint64_t clan_id) {
if (SteamFriends() == NULL) {
return "";
}
clan_activity = (uint64)clan_id;
return String::utf8(SteamFriends()->GetClanTag(clan_activity));
}
// Gets the Steam ID of the recently played with user at the given index.
uint64_t Steam::getCoplayFriend(int friend_number) {
if (SteamFriends() == NULL) {
return 0;
}
CSteamID friend_id = SteamFriends()->GetCoplayFriend(friend_number);
return friend_id.ConvertToUint64();
}
// Gets the number of players that the current users has recently played with, across all games. This is used for iteration, after calling this then GetCoplayFriend can be used to get the Steam ID of each player. These players are have been set with previous calls to SetPlayedWith.
int Steam::getCoplayFriendCount() {
if (SteamFriends() == NULL) {
return 0;
}
return SteamFriends()->GetCoplayFriendCount();
}
// Gets the number of users following the specified user.
void Steam::getFollowerCount(uint64_t steam_id) {
if (SteamFriends() != NULL) {
CSteamID user_id = (uint64)steam_id;
SteamAPICall_t api_call = SteamFriends()->GetFollowerCount(user_id);
callResultFollowerCount.Set(api_call, this, &Steam::get_follower_count);
}
}
// Returns the Steam ID of a user.
uint64_t Steam::getFriendByIndex(int friend_number, BitField<FriendFlags> friend_flags) {
if (SteamFriends() == NULL) {
return 0;
}
CSteamID friend_id = SteamFriends()->GetFriendByIndex(friend_number, (int)friend_flags);
return friend_id.ConvertToUint64();
}
// Gets the app ID of the game that user played with someone on their recently-played-with list.
uint32 Steam::getFriendCoplayGame(uint64_t friend_id) {
if (SteamFriends() == NULL) {
return 0;
}
CSteamID steam_id = (uint64)friend_id;
return SteamFriends()->GetFriendCoplayGame(steam_id);
}
// Gets the timestamp of when the user played with someone on their recently-played-with list. The time is provided in Unix epoch format (seconds since Jan 1st 1970).
int Steam::getFriendCoplayTime(uint64_t friend_id) {
if (SteamFriends() == NULL) {
return 0;
}
CSteamID steam_id = (uint64)friend_id;
return SteamFriends()->GetFriendCoplayTime(steam_id);
}
// Get number of friends user has.
int Steam::getFriendCount(int friend_flags) {
if (SteamFriends() == NULL) {
return 0;
}
return SteamFriends()->GetFriendCount(friend_flags);
}
// Iterators for getting users in a chat room, lobby, game server or clan.
int Steam::getFriendCountFromSource(uint64_t source_id) {
if (SteamFriends() == NULL) {
return 0;
}
CSteamID source = (uint64)source_id;
return SteamFriends()->GetFriendCountFromSource(source);
}
// Gets the Steam ID at the given index from a source (Steam group, chat room, lobby, or game server).
uint64_t Steam::getFriendFromSourceByIndex(uint64_t source_id, int friend_number) {
if (SteamFriends() == NULL) {
return 0;
}
CSteamID source = (uint64)source_id;
CSteamID friend_id = SteamFriends()->GetFriendFromSourceByIndex(source, friend_number);
return friend_id.ConvertToUint64();
}
// Returns dictionary of friend game played if valid
Dictionary Steam::getFriendGamePlayed(uint64_t steam_id) {
Dictionary friend_game;
if (SteamFriends() == NULL) {
return friend_game;
}
FriendGameInfo_t game_info;
CSteamID user_id = (uint64)steam_id;
bool success = SteamFriends()->GetFriendGamePlayed(user_id, &game_info);
// If successful
if (success) {
// Is there a valid lobby?
if (game_info.m_steamIDLobby.IsValid()) {
friend_game["id"] = game_info.m_gameID.AppID();
// Convert the IP address back to a string
const int NBYTES = 4;
uint8 octet[NBYTES];
char gameIP[16];
for (int j = 0; j < NBYTES; j++) {
octet[j] = game_info.m_unGameIP >> (j * 8);
}
sprintf(gameIP, "%d.%d.%d.%d", octet[0], octet[1], octet[2], octet[3]);
friend_game["ip"] = gameIP;
friend_game["game_port"] = game_info.m_usGamePort;
friend_game["query_port"] = (char)game_info.m_usQueryPort;
friend_game["lobby"] = uint64_t(game_info.m_steamIDLobby.ConvertToUint64());
} else {
friend_game["id"] = game_info.m_gameID.AppID();
friend_game["ip"] = "0.0.0.0";
friend_game["game_port"] = "0";
friend_game["query_port"] = "0";
friend_game["lobby"] = "No valid lobby";
}
}
return friend_game;
}
// Gets the data from a Steam friends message. This should only ever be called in response to a GameConnectedFriendChatMsg_t callback.
Dictionary Steam::getFriendMessage(uint64_t friend_id, int message) {
Dictionary chat;
if (SteamFriends() == NULL) {
return chat;
}
char text[STEAM_LARGE_BUFFER_SIZE];
EChatEntryType type = k_EChatEntryTypeInvalid;
chat["ret"] = SteamFriends()->GetFriendMessage(createSteamID(friend_id), message, text, STEAM_LARGE_BUFFER_SIZE, &type);
chat["text"] = String(text);
return chat;
}
// Get given friend's Steam username.
String Steam::getFriendPersonaName(uint64_t steam_id) {
if (SteamFriends() != NULL && steam_id > 0) {
CSteamID user_id = (uint64)steam_id;
bool is_data_loading = SteamFriends()->RequestUserInformation(user_id, true);
if (!is_data_loading) {
return String::utf8(SteamFriends()->GetFriendPersonaName(user_id));
}
}
return "";
}
// Accesses old friends names; returns an empty string when there are no more items in the history.
String Steam::getFriendPersonaNameHistory(uint64_t steam_id, int name_history) {
if (SteamFriends() == NULL) {
return "";
}
CSteamID user_id = (uint64)steam_id;
return String::utf8(SteamFriends()->GetFriendPersonaNameHistory(user_id, name_history));