-
Notifications
You must be signed in to change notification settings - Fork 103
/
Copy pathdll.cpp
1600 lines (1365 loc) · 58.9 KB
/
dll.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
/* Copyright (C) 2019 Mr Goldberg
This file is part of the Goldberg Emulator
The Goldberg Emulator is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
The Goldberg Emulator is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the Goldberg Emulator; if not, see
<http://www.gnu.org/licenses/>. */
#define STEAM_API_FUNCTIONS_IMPL
#include "dll/dll.h"
#include "dll/settings_parser.h"
#include "dll/client_known_interfaces.h"
static char old_client[128] = STEAMCLIENT_INTERFACE_VERSION; //"SteamClient017";
static char old_gameserver_stats[128] = STEAMGAMESERVERSTATS_INTERFACE_VERSION; //"SteamGameServerStats001";
static char old_gameserver[128] = STEAMGAMESERVER_INTERFACE_VERSION; //"SteamGameServer012";
static char old_matchmaking_servers[128] = STEAMMATCHMAKINGSERVERS_INTERFACE_VERSION; //"SteamMatchMakingServers002";
static char old_matchmaking[128] = STEAMMATCHMAKING_INTERFACE_VERSION; //"SteamMatchMaking009";
static char old_user[128] = STEAMUSER_INTERFACE_VERSION; //"SteamUser018";
static char old_friends[128] = STEAMFRIENDS_INTERFACE_VERSION; //"SteamFriends015";
static char old_utils[128] = STEAMUTILS_INTERFACE_VERSION; //"SteamUtils007";
static char old_userstats[128] = STEAMUSERSTATS_INTERFACE_VERSION; //"STEAMUSERSTATS_INTERFACE_VERSION011";
static char old_apps[128] = STEAMAPPS_INTERFACE_VERSION; //"STEAMAPPS_INTERFACE_VERSION007";
static char old_networking[128] = STEAMNETWORKING_INTERFACE_VERSION; //"SteamNetworking005";
static char old_remote_storage_interface[128] = STEAMREMOTESTORAGE_INTERFACE_VERSION; //"STEAMREMOTESTORAGE_INTERFACE_VERSION013";
static char old_screenshots[128] = STEAMSCREENSHOTS_INTERFACE_VERSION; //"STEAMSCREENSHOTS_INTERFACE_VERSION002";
static char old_http[128] = STEAMHTTP_INTERFACE_VERSION; //"STEAMHTTP_INTERFACE_VERSION002";
static char old_unified_messages[128] = STEAMUNIFIEDMESSAGES_INTERFACE_VERSION; //"STEAMUNIFIEDMESSAGES_INTERFACE_VERSION001";
static char old_controller[128] = STEAMCONTROLLER_INTERFACE_VERSION; //"SteamController003";
static char old_ugc_interface[128] = STEAMUGC_INTERFACE_VERSION; //"STEAMUGC_INTERFACE_VERSION007";
static char old_applist[128] = STEAMAPPLIST_INTERFACE_VERSION; //"STEAMAPPLIST_INTERFACE_VERSION001";
static char old_music[128] = STEAMMUSIC_INTERFACE_VERSION; //"STEAMMUSIC_INTERFACE_VERSION001";
static char old_music_remote[128] = STEAMMUSICREMOTE_INTERFACE_VERSION; //"STEAMMUSICREMOTE_INTERFACE_VERSION001";
static char old_html_surface[128] = STEAMHTMLSURFACE_INTERFACE_VERSION; //"STEAMHTMLSURFACE_INTERFACE_VERSION_003";
static char old_inventory[128] = STEAMINVENTORY_INTERFACE_VERSION; //"STEAMINVENTORY_INTERFACE_V001";
static char old_video[128] = STEAMVIDEO_INTERFACE_VERSION; //"STEAMVIDEO_INTERFACE_V001";
static char old_masterserver_updater[128] = STEAMMASTERSERVERUPDATER_INTERFACE_VERSION; //"SteamMasterServerUpdater001";
static ISteamUser *old_user_instance{};
static ISteamFriends *old_friends_interface{};
static ISteamUtils *old_utils_interface{};
static ISteamMatchmaking *old_matchmaking_instance{};
static ISteamUserStats *old_userstats_instance{};
static ISteamApps *old_apps_instance{};
static ISteamMatchmakingServers *old_matchmakingservers_instance{};
static ISteamNetworking *old_networking_instance{};
static ISteamRemoteStorage *old_remotestorage_instance{};
static ISteamScreenshots *old_screenshots_instance{};
static ISteamHTTP *old_http_instance{};
static ISteamController *old_controller_instance{};
static ISteamUGC *old_ugc_instance{};
static ISteamAppList *old_applist_instance{};
static ISteamMusic *old_music_instance{};
static ISteamMusicRemote *old_musicremote_instance{};
static ISteamHTMLSurface *old_htmlsurface_instance{};
static ISteamInventory *old_inventory_instance{};
static ISteamVideo *old_video_instance{};
static ISteamParentalSettings *old_parental_instance{};
static ISteamUnifiedMessages *old_unified_instance{};
static ISteamGameServer *old_gameserver_instance{};
static ISteamUtils *old_gamserver_utils_instance{};
static ISteamNetworking *old_gamserver_networking_instance{};
static ISteamGameServerStats *old_gamserver_stats_instance{};
static ISteamHTTP *old_gamserver_http_instance{};
static ISteamInventory *old_gamserver_inventory_instance{};
static ISteamUGC *old_gamserver_ugc_instance{};
static ISteamApps *old_gamserver_apps_instance{};
static ISteamMasterServerUpdater *old_gamserver_masterupdater_instance{};
static void load_old_steam_interfaces()
{
static bool loaded = false;
std::lock_guard lck(global_mutex);
if (loaded) return;
loaded = true;
const auto &old_itfs_map = settings_old_interfaces();
#define SET_OLD_ITF(sitf, var) do { \
auto itr = old_itfs_map.find(sitf); \
if (old_itfs_map.end() != itr && itr->second.size()) { \
memset(var, 0, sizeof(var)); \
itr->second.copy(var, sizeof(var) - 1); \
PRINT_DEBUG("set old interface: '%s'", itr->second.c_str()); \
} \
} while (0)
SET_OLD_ITF(SettingsItf::CLIENT, old_client);
SET_OLD_ITF(SettingsItf::GAMESERVER_STATS, old_gameserver_stats);
SET_OLD_ITF(SettingsItf::GAMESERVER, old_gameserver);
SET_OLD_ITF(SettingsItf::MATCHMAKING_SERVERS, old_matchmaking_servers);
SET_OLD_ITF(SettingsItf::MATCHMAKING, old_matchmaking);
SET_OLD_ITF(SettingsItf::USER, old_user);
SET_OLD_ITF(SettingsItf::FRIENDS, old_friends);
SET_OLD_ITF(SettingsItf::UTILS, old_utils);
SET_OLD_ITF(SettingsItf::USER_STATS, old_userstats);
SET_OLD_ITF(SettingsItf::APPS, old_apps);
SET_OLD_ITF(SettingsItf::NETWORKING, old_networking);
SET_OLD_ITF(SettingsItf::REMOTE_STORAGE, old_remote_storage_interface);
SET_OLD_ITF(SettingsItf::SCREENSHOTS, old_screenshots);
SET_OLD_ITF(SettingsItf::HTTP, old_http);
SET_OLD_ITF(SettingsItf::UNIFIED_MESSAGES, old_unified_messages);
SET_OLD_ITF(SettingsItf::CONTROLLER, old_controller);
SET_OLD_ITF(SettingsItf::UGC, old_ugc_interface);
SET_OLD_ITF(SettingsItf::APPLIST, old_applist);
SET_OLD_ITF(SettingsItf::MUSIC, old_music);
SET_OLD_ITF(SettingsItf::MUSIC_REMOTE, old_music_remote);
SET_OLD_ITF(SettingsItf::HTML_SURFACE, old_html_surface);
SET_OLD_ITF(SettingsItf::INVENTORY, old_inventory);
SET_OLD_ITF(SettingsItf::VIDEO, old_video);
SET_OLD_ITF(SettingsItf::MASTERSERVER_UPDATER, old_masterserver_updater);
#undef SET_OLD_ITF
PRINT_DEBUG("Old interfaces:");
PRINT_DEBUG(" client: %s", old_client);
PRINT_DEBUG(" gameserver stats: %s", old_gameserver_stats);
PRINT_DEBUG(" gameserver: %s", old_gameserver);
PRINT_DEBUG(" matchmaking servers: %s", old_matchmaking_servers);
PRINT_DEBUG(" matchmaking: %s", old_matchmaking);
PRINT_DEBUG(" user: %s", old_user);
PRINT_DEBUG(" friends: %s", old_friends);
PRINT_DEBUG(" utils: %s", old_utils);
PRINT_DEBUG(" userstats: %s", old_userstats);
PRINT_DEBUG(" apps: %s", old_apps);
PRINT_DEBUG(" networking: %s", old_networking);
PRINT_DEBUG(" remote storage: %s", old_remote_storage_interface);
PRINT_DEBUG(" screenshots: %s", old_screenshots);
PRINT_DEBUG(" http: %s", old_http);
PRINT_DEBUG(" unified messages: %s", old_unified_messages);
PRINT_DEBUG(" controller %s", old_controller);
PRINT_DEBUG(" ugc: %s", old_ugc_interface);
PRINT_DEBUG(" applist: %s", old_applist);
PRINT_DEBUG(" music: %s", old_music);
PRINT_DEBUG(" music remote: %s", old_music_remote);
PRINT_DEBUG(" html surface: %s", old_html_surface);
PRINT_DEBUG(" inventory: %s", old_inventory);
PRINT_DEBUG(" video: %s", old_video);
PRINT_DEBUG(" masterserver updater: %s", old_masterserver_updater);
reset_LastError();
}
//steam_api_internal.h
STEAMAPI_API HSteamUser SteamAPI_GetHSteamUser()
{
PRINT_DEBUG_ENTRY();
if (!get_steam_client()->IsUserLogIn()) return 0;
return CLIENT_HSTEAMUSER;
}
// declare "g_pSteamClientGameServer" as an export for API library, then actually define it
#if !defined(STEAMCLIENT_DLL) // api
STEAMAPI_API ISteamClient *g_pSteamClientGameServer;
#endif
ISteamClient *g_pSteamClientGameServer{};
static Steam_Client *steamclient_instance{};
Steam_Client *get_steam_client()
{
if (!steamclient_instance) {
std::lock_guard<std::recursive_mutex> lock(global_mutex);
// if we win the thread arbitration for the first time, this will still be null
if (!steamclient_instance) {
load_old_steam_interfaces();
steamclient_instance = new Steam_Client();
}
}
return steamclient_instance;
}
void destroy_client()
{
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (steamclient_instance) {
delete steamclient_instance;
steamclient_instance = nullptr;
}
}
Steam_Client *get_steam_client_old()
{
return get_steam_client();
}
Steam_Client *get_steam_clientserver_old()
{
return get_steam_client();
}
static bool steamclient_has_ipv6_functions_flag{};
bool steamclient_has_ipv6_functions()
{
return get_steam_client()->gameserver_has_ipv6_functions || steamclient_has_ipv6_functions_flag;
}
static void *create_client_interface(const char *ver)
{
std::lock_guard<std::recursive_mutex> lock(global_mutex);
Steam_Client *client_ptr = get_steam_client();
if (strstr(ver, "SteamClient") == ver) {
if (strcmp(ver, "SteamClient006") == 0) {
return static_cast<ISteamClient006 *>(client_ptr);
} else if (strcmp(ver, "SteamClient007") == 0) {
return static_cast<ISteamClient007 *>(client_ptr);
} else if (strcmp(ver, "SteamClient008") == 0) {
return static_cast<ISteamClient008 *>(client_ptr);
} else if (strcmp(ver, "SteamClient009") == 0) {
return static_cast<ISteamClient009 *>(client_ptr);
} else if (strcmp(ver, "SteamClient010") == 0) {
return static_cast<ISteamClient010 *>(client_ptr);
} else if (strcmp(ver, "SteamClient011") == 0) {
return static_cast<ISteamClient011 *>(client_ptr);
} else if (strcmp(ver, "SteamClient012") == 0) {
return static_cast<ISteamClient012 *>(client_ptr);
} else if (strcmp(ver, "SteamClient013") == 0) {
return static_cast<ISteamClient013 *>(client_ptr);
} else if (strcmp(ver, "SteamClient014") == 0) {
return static_cast<ISteamClient014 *>(client_ptr);
} else if (strcmp(ver, "SteamClient015") == 0) {
return static_cast<ISteamClient015 *>(client_ptr);
} else if (strcmp(ver, "SteamClient016") == 0) {
return static_cast<ISteamClient016 *>(client_ptr);
} else if (strcmp(ver, "SteamClient017") == 0) {
return static_cast<ISteamClient017 *>(client_ptr);
} else if (strcmp(ver, "SteamClient018") == 0) {
return static_cast<ISteamClient018 *>(client_ptr);
} else if (strcmp(ver, "SteamClient019") == 0) {
return static_cast<ISteamClient019 *>(client_ptr);
}
steamclient_has_ipv6_functions_flag = true;
if (strcmp(ver, "SteamClient020") == 0) {
return static_cast<ISteamClient020 *>(client_ptr);
} else if (strcmp(ver, STEAMCLIENT_INTERFACE_VERSION) == 0) {
return static_cast<ISteamClient *>(client_ptr);
}
}
client_ptr->report_missing_impl_and_exit(ver, EMU_FUNC_NAME);
}
STEAMAPI_API void * S_CALLTYPE SteamInternal_CreateInterface( const char *ver )
{
PRINT_DEBUG("%s", ver);
if (!get_steam_client()->IsUserLogIn() && !get_steam_client()->IsServerInit()) return NULL;
return create_client_interface(ver);
}
static uintp global_counter{};
struct ContextInitData {
void (*pFn)(void* pCtx) = nullptr;
uintp counter{};
CSteamAPIContext ctx{};
};
STEAMAPI_API void * S_CALLTYPE SteamInternal_ContextInit( void *pContextInitData )
{
//PRINT_DEBUG_ENTRY();
struct ContextInitData *contextInitData = (struct ContextInitData *)pContextInitData;
if (contextInitData->counter != global_counter) {
PRINT_DEBUG("initializing");
contextInitData->pFn(&contextInitData->ctx);
contextInitData->counter = global_counter;
}
return &contextInitData->ctx;
}
//steam_api.h
// Initialize the Steamworks SDK.
// On success k_ESteamAPIInitResult_OK is returned. Otherwise, if pOutErrMsg is non-NULL,
// it will receive a non-localized message that explains the reason for the failure
//
// Example usage:
//
// SteamErrMsg errMsg;
// if ( SteamAPI_Init(&errMsg) != k_ESteamAPIInitResult_OK )
// FatalError( "Failed to init Steam. %s", errMsg );
STEAMAPI_API ESteamAPIInitResult S_CALLTYPE SteamInternal_SteamAPI_Init( const char *pszInternalCheckInterfaceVersions, SteamErrMsg *pOutErrMsg )
{
PRINT_DEBUG("%s", pszInternalCheckInterfaceVersions);
if (SteamAPI_Init()) {
return ESteamAPIInitResult::k_ESteamAPIInitResult_OK;
}
if (pOutErrMsg) {
constexpr const static char err[] = "SteamInitEx failed";
memcpy(*pOutErrMsg, err, sizeof(err));
}
return ESteamAPIInitResult::k_ESteamAPIInitResult_FailedGeneric;
}
STEAMAPI_API ESteamAPIInitResult S_CALLTYPE SteamAPI_InitFlat( SteamErrMsg *pOutErrMsg )
{
PRINT_DEBUG_ENTRY();
if (SteamAPI_Init()) {
return ESteamAPIInitResult::k_ESteamAPIInitResult_OK;
}
if (pOutErrMsg) {
constexpr const static char err[] = "SteamAPI_InitFlat failed";
memcpy(*pOutErrMsg, err, sizeof(err));
}
return ESteamAPIInitResult::k_ESteamAPIInitResult_FailedGeneric;
}
// SteamAPI_Init must be called before using any other API functions. If it fails, an
// error message will be output to the debugger (or stderr) with further information.
static HSteamPipe user_steam_pipe = 0;
STEAMAPI_API steam_bool S_CALLTYPE SteamAPI_Init()
{
PRINT_DEBUG_ENTRY();
if (user_steam_pipe) return true;
// call this first since it loads old interfaces
Steam_Client* client = get_steam_client();
#ifdef EMU_EXPERIMENTAL_BUILD
crack_SteamAPI_Init();
#endif
user_steam_pipe = client->CreateSteamPipe();
client->ConnectToGlobalUser(user_steam_pipe);
global_counter++;
return true;
}
//TODO: not sure if this is the right signature for this function.
STEAMAPI_API steam_bool S_CALLTYPE SteamAPI_InitAnonymousUser()
{
PRINT_DEBUG_ENTRY();
return SteamAPI_Init();
}
// SteamAPI_Shutdown should be called during process shutdown if possible.
STEAMAPI_API void S_CALLTYPE SteamAPI_Shutdown()
{
PRINT_DEBUG_ENTRY();
// if nothing is initialized just return, see the note in SteamGameServer_Shutdown()
// guard against sloppy games programming
// don't shutdown if this isn't a client app (maybe gameserver?)
if (!user_steam_pipe &&
!(steamclient_instance && steamclient_instance->IsUserLogIn())) {
PRINT_DEBUG("[WARNING] app is trying to shutdown as client, but it isn't initialzed (is this a gameserver?)");
return;
}
get_steam_client()->clientShutdown();
get_steam_client()->BReleaseSteamPipe(user_steam_pipe);
get_steam_client()->BShutdownIfAllPipesClosed();
user_steam_pipe = 0;
--global_counter;
old_user_instance = NULL;
old_friends_interface = NULL;
old_utils_interface = NULL;
old_matchmaking_instance = NULL;
old_userstats_instance = NULL;
old_apps_instance = NULL;
old_matchmakingservers_instance = NULL;
old_networking_instance = NULL;
old_remotestorage_instance = NULL;
old_screenshots_instance = NULL;
old_http_instance = NULL;
old_controller_instance = NULL;
old_ugc_instance = NULL;
old_applist_instance = NULL;
old_music_instance = NULL;
old_musicremote_instance = NULL;
old_htmlsurface_instance = NULL;
old_inventory_instance = NULL;
old_video_instance = NULL;
old_parental_instance = NULL;
old_unified_instance = NULL;
if (global_counter == 0) {
destroy_client();
}
}
// SteamAPI_RestartAppIfNecessary ensures that your executable was launched through Steam.
//
// Returns true if the current process should terminate. Steam is now re-launching your application.
//
// Returns false if no action needs to be taken. This means that your executable was started through
// the Steam client, or a steam_appid.txt file is present in your game's directory (for development).
// Your current process should continue if false is returned.
//
// NOTE: If you use the Steam DRM wrapper on your primary executable file, this check is unnecessary
// since the DRM wrapper will ensure that your application was launched properly through Steam.
// ------------------------
// --- older notes/docs ---
// note that this usually means we're dealing with CEG!
// ------------------------
// Detects if your executable was launched through the Steam client, and restarts your game through
// the client if necessary. The Steam client will be started if it is not running.
//
// Returns: true if your executable was NOT launched through the Steam client. This function will
// then start your application through the client. Your current process should exit.
//
// false if your executable was started through the Steam client or a steam_appid.txt file
// is present in your game's directory (for development). Your current process should continue.
//
// NOTE: This function should be used only if you are using CEG or not using Steam's DRM. Once applied
// to your executable, Steam's DRM will handle restarting through Steam if necessary.
STEAMAPI_API steam_bool S_CALLTYPE SteamAPI_RestartAppIfNecessary( uint32 unOwnAppID )
{
PRINT_DEBUG("%u", unOwnAppID);
// call this first since it loads old interfaces
Steam_Client* client = get_steam_client();
#ifdef EMU_EXPERIMENTAL_BUILD
crack_SteamAPI_RestartAppIfNecessary(unOwnAppID);
#endif
client->setAppID(unOwnAppID);
return false;
}
// Many Steam API functions allocate a small amount of thread-local memory for parameter storage.
// SteamAPI_ReleaseCurrentThreadMemory() will free API memory associated with the calling thread.
// This function is also called automatically by SteamAPI_RunCallbacks(), so a single-threaded
// program never needs to explicitly call this function.
STEAMAPI_API void S_CALLTYPE SteamAPI_ReleaseCurrentThreadMemory()
{
PRINT_DEBUG_TODO();
}
// crash dump recording functions
STEAMAPI_API void S_CALLTYPE SteamAPI_WriteMiniDump( uint32 uStructuredExceptionCode, void* pvExceptionInfo, uint32 uBuildID )
{
PRINT_DEBUG_TODO();
PRINT_DEBUG(" app is writing a crash dump! [XXXXXXXXXXXXXXXXXXXXXXXXXXX]");
}
STEAMAPI_API void S_CALLTYPE SteamAPI_SetMiniDumpComment( const char *pchMsg )
{
PRINT_DEBUG_TODO();
PRINT_DEBUG( "%s", pchMsg);
}
//----------------------------------------------------------------------------------------------------------------------------------------------------------//
// steam callback and call-result helpers
//
// The following macros and classes are used to register your application for
// callbacks and call-results, which are delivered in a predictable manner.
//
// STEAM_CALLBACK macros are meant for use inside of a C++ class definition.
// They map a Steam notification callback directly to a class member function
// which is automatically prototyped as "void func( callback_type *pParam )".
//
// CCallResult is used with specific Steam APIs that return "result handles".
// The handle can be passed to a CCallResult object's Set function, along with
// an object pointer and member-function pointer. The member function will
// be executed once the results of the Steam API call are available.
//
// CCallback and CCallbackManual classes can be used instead of STEAM_CALLBACK
// macros if you require finer control over registration and unregistration.
//
// Callbacks and call-results are queued automatically and are only
// delivered/executed when your application calls SteamAPI_RunCallbacks().
//----------------------------------------------------------------------------------------------------------------------------------------------------------//
// SteamAPI_RunCallbacks is safe to call from multiple threads simultaneously,
// but if you choose to do this, callback code could be executed on any thread.
// One alternative is to call SteamAPI_RunCallbacks from the main thread only,
// and call SteamAPI_ReleaseCurrentThreadMemory regularly on other threads.
STEAMAPI_API void S_CALLTYPE SteamAPI_RunCallbacks()
{
// PRINT_DEBUG_ENTRY();
get_steam_client()->RunCallbacks(true, false);
//std::this_thread::sleep_for(std::chrono::microseconds(1)); //fixes resident evil revelations lagging. (Seems to work fine without this right now, commenting out)
}
// Declares a callback member function plus a helper member variable which
// registers the callback on object creation and unregisters on destruction.
// The optional fourth 'var' param exists only for backwards-compatibility
// and can be ignored.
//#define STEAM_CALLBACK( thisclass, func, .../*callback_type, [deprecated] var*/ ) \
// _STEAM_CALLBACK_SELECT( ( __VA_ARGS__, 4, 3 ), ( /**/, thisclass, func, __VA_ARGS__ ) )
// Declares a callback function and a named CCallbackManual variable which
// has Register and Unregister functions instead of automatic registration.
//#define STEAM_CALLBACK_MANUAL( thisclass, func, callback_type, var ) \
// CCallbackManual< thisclass, callback_type > var; void func( callback_type *pParam )
// Internal functions used by the utility CCallback objects to receive callbacks
STEAMAPI_API void S_CALLTYPE SteamAPI_RegisterCallback( class CCallbackBase *pCallback, int iCallback )
{
PRINT_DEBUG("%p %u funct:%u", pCallback, iCallback, pCallback->GetICallback());
std::lock_guard<std::recursive_mutex> lock(global_mutex);
get_steam_client()->RegisterCallback(pCallback, iCallback);
}
STEAMAPI_API void S_CALLTYPE SteamAPI_UnregisterCallback( class CCallbackBase *pCallback )
{
PRINT_DEBUG("%p", pCallback);
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (!steamclient_instance) return;
get_steam_client()->UnregisterCallback(pCallback);
}
// Internal functions used by the utility CCallResult objects to receive async call results
STEAMAPI_API void S_CALLTYPE SteamAPI_RegisterCallResult( class CCallbackBase *pCallback, SteamAPICall_t hAPICall )
{
PRINT_DEBUG("%llu %p", hAPICall, pCallback);
if (!hAPICall)
return;
get_steam_client()->RegisterCallResult(pCallback, hAPICall);
}
STEAMAPI_API void S_CALLTYPE SteamAPI_UnregisterCallResult( class CCallbackBase *pCallback, SteamAPICall_t hAPICall )
{
PRINT_DEBUG_ENTRY();
if (!hAPICall)
return;
if (!steamclient_instance) return;
get_steam_client()->UnregisterCallResult(pCallback, hAPICall);
}
STEAMAPI_API void *S_CALLTYPE SteamInternal_FindOrCreateUserInterface( HSteamUser hSteamUser, const char *pszVersion )
{
PRINT_DEBUG("%i %s", hSteamUser, pszVersion);
return get_steam_client()->GetISteamGenericInterface(hSteamUser, SteamAPI_GetHSteamPipe(), pszVersion);
}
STEAMAPI_API void *S_CALLTYPE SteamInternal_FindOrCreateGameServerInterface( HSteamUser hSteamUser, const char *pszVersion )
{
PRINT_DEBUG("%i %s", hSteamUser, pszVersion);
return get_steam_client()->GetISteamGenericInterface(hSteamUser, SteamGameServer_GetHSteamPipe(), pszVersion);
}
//----------------------------------------------------------------------------------------------------------------------------------------------------------//
// steamclient.dll private wrapper functions
//
// The following functions are part of abstracting API access to the steamclient.dll, but should only be used in very specific cases
//----------------------------------------------------------------------------------------------------------------------------------------------------------//
// SteamAPI_IsSteamRunning() returns true if Steam is currently running
STEAMAPI_API steam_bool S_CALLTYPE SteamAPI_IsSteamRunning()
{
PRINT_DEBUG_ENTRY();
return true;
}
// Pumps out all the steam messages, calling registered callbacks.
// NOT THREADSAFE - do not call from multiple threads simultaneously.
STEAMAPI_API void Steam_RunCallbacks( HSteamPipe hSteamPipe, bool bGameServerCallbacks )
{
// PRINT_DEBUG_ENTRY();
SteamAPI_RunCallbacks();
if (bGameServerCallbacks)
SteamGameServer_RunCallbacks();
}
// register the callback funcs to use to interact with the steam dll
STEAMAPI_API void Steam_RegisterInterfaceFuncs( void *hModule )
{
PRINT_DEBUG_TODO();
}
// returns the HSteamUser of the last user to dispatch a callback
STEAMAPI_API HSteamUser Steam_GetHSteamUserCurrent()
{
PRINT_DEBUG_ENTRY();
//TODO
return SteamAPI_GetHSteamUser();
}
// returns the filename path of the current running Steam process, used if you need to load an explicit steam dll by name.
// DEPRECATED - implementation is Windows only, and the path returned is a UTF-8 string which must be converted to UTF-16 for use with Win32 APIs
STEAMAPI_API const char *SteamAPI_GetSteamInstallPath()
{
PRINT_DEBUG_ENTRY();
static char steam_folder[4096]{};
std::string path(get_env_variable("SteamPath"));
if (path.empty()) {
path = Local_Storage::get_program_path();
}
auto count = path.copy(steam_folder, sizeof(steam_folder) - 1);
steam_folder[count] = '\0';
PRINT_DEBUG("returned path '%s'", steam_folder);
return steam_folder;
}
// returns the pipe we are communicating to Steam with
STEAMAPI_API HSteamPipe SteamAPI_GetHSteamPipe()
{
PRINT_DEBUG_ENTRY();
return user_steam_pipe;
}
// sets whether or not Steam_RunCallbacks() should do a try {} catch (...) {} around calls to issuing callbacks
STEAMAPI_API void SteamAPI_SetTryCatchCallbacks( bool bTryCatchCallbacks )
{
PRINT_DEBUG_TODO();
}
// backwards compat export, passes through to SteamAPI_ variants
STEAMAPI_API HSteamPipe GetHSteamPipe()
{
PRINT_DEBUG_ENTRY();
return SteamAPI_GetHSteamPipe();
}
STEAMAPI_API HSteamUser GetHSteamUser()
{
PRINT_DEBUG_ENTRY();
return SteamAPI_GetHSteamUser();
}
// exists only for backwards compat with code written against older SDKs
STEAMAPI_API steam_bool S_CALLTYPE SteamAPI_InitSafe()
{
PRINT_DEBUG_ENTRY();
return SteamAPI_Init();
}
STEAMAPI_API ISteamClient *SteamClient()
{
PRINT_DEBUG("old");
// call this first since it loads old interfaces
Steam_Client* client = get_steam_client();
if (!client->IsUserLogIn()) return NULL;
return (ISteamClient *)SteamInternal_CreateInterface(old_client);
}
#define CACHE_OLDSTEAM_INSTANCE(variable, get_func) { if (variable) return variable; else return variable = (get_func); }
STEAMAPI_API ISteamUser *SteamUser()
{
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_user_instance, get_steam_client_old()->GetISteamUser(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), old_user))
}
STEAMAPI_API ISteamFriends *SteamFriends()
{
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_friends_interface, get_steam_client_old()->GetISteamFriends(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), old_friends ))
}
STEAMAPI_API ISteamUtils *SteamUtils()
{
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_utils_interface, get_steam_client_old()->GetISteamUtils(SteamAPI_GetHSteamPipe(), old_utils))
}
STEAMAPI_API ISteamMatchmaking *SteamMatchmaking()
{
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_matchmaking_instance, get_steam_client_old()->GetISteamMatchmaking(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), old_matchmaking))
}
STEAMAPI_API ISteamUserStats *SteamUserStats()
{
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_userstats_instance, get_steam_client_old()->GetISteamUserStats(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), old_userstats))
}
STEAMAPI_API ISteamApps *SteamApps()
{
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_apps_instance, get_steam_client_old()->GetISteamApps(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), old_apps))
}
STEAMAPI_API ISteamMatchmakingServers *SteamMatchmakingServers()
{
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_matchmakingservers_instance, get_steam_client_old()->GetISteamMatchmakingServers(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), old_matchmaking_servers))
}
STEAMAPI_API ISteamNetworking *SteamNetworking()
{
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_networking_instance, get_steam_client_old()->GetISteamNetworking(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), old_networking))
}
STEAMAPI_API ISteamRemoteStorage *SteamRemoteStorage()
{
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_remotestorage_instance, get_steam_client_old()->GetISteamRemoteStorage(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), old_remote_storage_interface))
}
STEAMAPI_API ISteamScreenshots *SteamScreenshots()
{
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_screenshots_instance, get_steam_client_old()->GetISteamScreenshots(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), old_screenshots))
}
STEAMAPI_API ISteamHTTP *SteamHTTP()
{
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_http_instance, get_steam_client_old()->GetISteamHTTP(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), old_http))
}
STEAMAPI_API ISteamController *SteamController()
{
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_controller_instance, get_steam_client_old()->GetISteamController(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), old_controller))
}
STEAMAPI_API ISteamUGC *SteamUGC()
{
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_ugc_instance, get_steam_client_old()->GetISteamUGC(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), old_ugc_interface ))
}
STEAMAPI_API ISteamAppList *SteamAppList()
{
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_applist_instance, get_steam_client_old()->GetISteamAppList(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), old_applist))
}
STEAMAPI_API ISteamMusic *SteamMusic()
{
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_music_instance, get_steam_client_old()->GetISteamMusic(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), old_music))
}
STEAMAPI_API ISteamMusicRemote *SteamMusicRemote()
{
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_musicremote_instance, get_steam_client_old()->GetISteamMusicRemote(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), old_music_remote))
}
STEAMAPI_API ISteamHTMLSurface *SteamHTMLSurface()
{
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_htmlsurface_instance, get_steam_client_old()->GetISteamHTMLSurface(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), old_html_surface))
}
STEAMAPI_API ISteamInventory *SteamInventory()
{
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_inventory_instance, get_steam_client_old()->GetISteamInventory(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), old_inventory))
}
STEAMAPI_API ISteamVideo *SteamVideo()
{
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_video_instance, get_steam_client_old()->GetISteamVideo(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), old_video))
}
STEAMAPI_API ISteamParentalSettings *SteamParentalSettings()
{
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_parental_instance, get_steam_client_old()->GetISteamParentalSettings(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), ""))
}
STEAMAPI_API ISteamUnifiedMessages *SteamUnifiedMessages()
{
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_unified_instance, get_steam_client_old()->GetISteamUnifiedMessages(SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), old_unified_messages))
}
STEAMAPI_API ISteamGameServer *SteamGameServer()
{
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_gameserver_instance, get_steam_clientserver_old()->GetISteamGameServer(SteamGameServer_GetHSteamUser(), SteamGameServer_GetHSteamPipe(), old_gameserver ))
}
STEAMAPI_API ISteamUtils *SteamGameServerUtils()
{
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_gamserver_utils_instance, get_steam_clientserver_old()->GetISteamUtils(SteamGameServer_GetHSteamPipe(), old_utils ))
}
STEAMAPI_API ISteamNetworking *SteamGameServerNetworking()
{
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_gamserver_networking_instance, get_steam_clientserver_old()->GetISteamNetworking(SteamGameServer_GetHSteamUser(), SteamGameServer_GetHSteamPipe(), old_networking ))
}
STEAMAPI_API ISteamGameServerStats *SteamGameServerStats()
{
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_gamserver_stats_instance, get_steam_clientserver_old()->GetISteamGameServerStats(SteamGameServer_GetHSteamUser(), SteamGameServer_GetHSteamPipe(), old_gameserver_stats ))
}
STEAMAPI_API ISteamHTTP *SteamGameServerHTTP()
{
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_gamserver_http_instance, get_steam_clientserver_old()->GetISteamHTTP(SteamGameServer_GetHSteamUser(), SteamGameServer_GetHSteamPipe(), old_http ))
}
STEAMAPI_API ISteamInventory *SteamGameServerInventory()
{
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_gamserver_inventory_instance, get_steam_clientserver_old()->GetISteamInventory(SteamGameServer_GetHSteamUser(), SteamGameServer_GetHSteamPipe(), old_inventory ))
}
STEAMAPI_API ISteamUGC *SteamGameServerUGC()
{
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_gamserver_ugc_instance, get_steam_clientserver_old()->GetISteamUGC(SteamGameServer_GetHSteamUser(), SteamGameServer_GetHSteamPipe(), old_ugc_interface ))
}
STEAMAPI_API ISteamApps *SteamGameServerApps()
{
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_gamserver_apps_instance, get_steam_clientserver_old()->GetISteamApps(SteamGameServer_GetHSteamUser(), SteamGameServer_GetHSteamPipe(), old_apps ))
}
STEAMAPI_API ISteamMasterServerUpdater *SteamMasterServerUpdater()
{
PRINT_DEBUG("old");
CACHE_OLDSTEAM_INSTANCE(old_gamserver_masterupdater_instance, get_steam_clientserver_old()->GetISteamMasterServerUpdater(SteamGameServer_GetHSteamUser(), SteamGameServer_GetHSteamPipe(), old_masterserver_updater))
}
#undef CACHE_OLDSTEAM_INSTANCE
//Gameserver stuff
STEAMAPI_API void * S_CALLTYPE SteamGameServerInternal_CreateInterface( const char *ver )
{
PRINT_DEBUG("%s", ver);
return SteamInternal_CreateInterface(ver);
}
static HSteamPipe server_steam_pipe = 0;
STEAMAPI_API HSteamPipe S_CALLTYPE SteamGameServer_GetHSteamPipe()
{
PRINT_DEBUG_ENTRY();
return server_steam_pipe;
}
STEAMAPI_API HSteamUser S_CALLTYPE SteamGameServer_GetHSteamUser()
{
PRINT_DEBUG_ENTRY();
if (!get_steam_client()->IsServerInit()) return 0;
return SERVER_HSTEAMUSER;
}
//See: SteamGameServer_Init
//STEAMAPI_API steam_bool S_CALLTYPE SteamGameServer_InitSafe(uint32 unIP, uint16 usSteamPort, uint16 usGamePort, uint16 usQueryPort, EServerMode eServerMode, const char *pchVersionString )
STEAMAPI_API steam_bool S_CALLTYPE SteamGameServer_InitSafe( uint32 unIP, uint16 usSteamPort, uint16 usGamePort, uint16 unknown, EServerMode eServerMode, void *unknown1, void *unknown2, void *unknown3 )
{
PRINT_DEBUG_ENTRY();
const char *pchVersionString{};
EServerMode serverMode{};
uint16 usQueryPort{};
// call this first since it loads old interfaces
Steam_Client* client = get_steam_client();
bool logon_anon = false;
if (strcmp(old_gameserver, "SteamGameServer010") == 0 || strstr(old_gameserver, "SteamGameServer00") == old_gameserver) {
PRINT_DEBUG("Old game server init safe");
pchVersionString = (char *)unknown3;
memcpy(&serverMode, &unknown1, sizeof(serverMode));
memcpy(&usQueryPort, (char *)&eServerMode, sizeof(usQueryPort));
logon_anon = true;
} else {
pchVersionString = (char *)unknown1;
serverMode = eServerMode;
usQueryPort = unknown;
}
bool ret = SteamInternal_GameServer_Init( unIP, usSteamPort, usGamePort, usQueryPort, serverMode, pchVersionString );
if (logon_anon) {
client->steam_gameserver->LogOnAnonymous();
}
return ret;
}
STEAMAPI_API ISteamClient *SteamGameServerClient();
STEAMAPI_API steam_bool S_CALLTYPE SteamInternal_GameServer_Init( uint32 unIP, uint16 usPort, uint16 usGamePort, uint16 usQueryPort, EServerMode eServerMode, const char *pchVersionString )
{
PRINT_DEBUG("%X %hu %hu %hu %u %s", unIP, usPort, usGamePort, usQueryPort, eServerMode, pchVersionString);
// call this first since it loads old interfaces
Steam_Client* client = get_steam_client();
if (!server_steam_pipe) {
client->CreateLocalUser(&server_steam_pipe, k_EAccountTypeGameServer);
++global_counter;
//g_pSteamClientGameServer is only used in pre 1.37 (where the interface versions are not provided by the game)
g_pSteamClientGameServer = SteamGameServerClient();
}
uint32 unFlags = 0;
if (eServerMode == eServerModeAuthenticationAndSecure) unFlags = k_unServerFlagSecure;
return client->steam_gameserver->InitGameServer(unIP, usGamePort, usQueryPort, unFlags, 0, pchVersionString);
}
STEAMAPI_API ESteamAPIInitResult S_CALLTYPE SteamInternal_GameServer_Init_V2( uint32 unIP, uint16 usGamePort, uint16 usQueryPort, EServerMode eServerMode, const char *pchVersionString, const char *pszInternalCheckInterfaceVersions, SteamErrMsg *pOutErrMsg )
{
PRINT_DEBUG("%u %hu %hu %u %s %s", unIP, usGamePort, usQueryPort, eServerMode, pchVersionString, pszInternalCheckInterfaceVersions);
if (SteamInternal_GameServer_Init(unIP, 0, usGamePort, usQueryPort, eServerMode, pchVersionString)) {
return ESteamAPIInitResult::k_ESteamAPIInitResult_OK;
}
if (pOutErrMsg) {
memcpy(*pOutErrMsg, "GameServer_V2 failed", 20);
(*pOutErrMsg)[20] = 0;
(*pOutErrMsg)[21] = 0;
}
return ESteamAPIInitResult::k_ESteamAPIInitResult_FailedGeneric;
}
//SteamGameServer004 and before:
//STEAMAPI_API steam_bool SteamGameServer_Init( uint32 unIP, uint16 usPort, uint16 usGamePort, uint16 usSpectatorPort, uint16 usQueryPort, EServerMode eServerMode, int nGameAppId, const char *pchGameDir, const char *pchVersionString );
//SteamGameServer010 and before:
//STEAMAPI_API steam_bool SteamGameServer_Init( uint32 unIP, uint16 usPort, uint16 usGamePort, uint16 usSpectatorPort, uint16 usQueryPort, EServerMode eServerMode, const char *pchGameDir, const char *pchVersionString );
//SteamGameServer011 and later:
//STEAMAPI_API steam_bool SteamGameServer_Init( uint32 unIP, uint16 usSteamPort, uint16 usGamePort, uint16 usQueryPort, EServerMode eServerMode, const char *pchVersionString );
//SteamGameServer015 and later:
//STEAMAPI_API steam_bool SteamGameServer_Init( uint32 unIP, uint16 usGamePort, uint16 usQueryPort, EServerMode eServerMode, const char *pchVersionString );
STEAMAPI_API steam_bool SteamGameServer_Init( uint32 unIP, uint16 usSteamPort, uint16 usGamePort, uint16 unknown, EServerMode eServerMode, void *unknown1, void *unknown2, void *unknown3 )
{
PRINT_DEBUG_ENTRY();
const char *pchVersionString{};
EServerMode serverMode{};
uint16 usQueryPort{};
// call this first since it loads old interfaces
Steam_Client* client = get_steam_client();
bool logon_anon = false;
if (strcmp(old_gameserver, "SteamGameServer010") == 0 || strstr(old_gameserver, "SteamGameServer00") == old_gameserver) {
PRINT_DEBUG("Old game server init");
pchVersionString = (char *)unknown3;
memcpy(&serverMode, &unknown1, sizeof(serverMode));
memcpy(&usQueryPort, (char *)&eServerMode, sizeof(usQueryPort));
logon_anon = true;
} else {
pchVersionString = (char *)unknown1;
serverMode = eServerMode;
usQueryPort = unknown;
}
bool ret = SteamInternal_GameServer_Init( unIP, usSteamPort, usGamePort, usQueryPort, serverMode, pchVersionString );
if (logon_anon) {
client->steam_gameserver->LogOnAnonymous();
}
return ret;
}
STEAMAPI_API void SteamGameServer_Shutdown()
{
PRINT_DEBUG_ENTRY();
// appid 35140 despite being a regular game (not a server) will still call this function
// its steam_api.dll (old api) will check first if "g_pSteamClientGameServer" is null, and if so it just returns
// hence avoiding sloppy programming
// if nothing is initialized just return
// don't shutdown if this isn't a gameserver app (maybe client?)
if (!server_steam_pipe &&
!g_pSteamClientGameServer && // old steam_api.dll checks for this
!(steamclient_instance && steamclient_instance->IsServerInit())) {
PRINT_DEBUG("[WARNING] app is trying to shutdown as gameserver, but it isn't initialzed (is this a client?)");
return;
}
get_steam_client()->serverShutdown();
get_steam_client()->BReleaseSteamPipe(server_steam_pipe);
get_steam_client()->BShutdownIfAllPipesClosed();
server_steam_pipe = 0;
--global_counter;
g_pSteamClientGameServer = NULL; // old steam_api.dll sets this to null when SteamGameServer_Shutdown is called
old_gameserver_instance = NULL;
old_gamserver_utils_instance = NULL;
old_gamserver_networking_instance = NULL;
old_gamserver_stats_instance = NULL;
old_gamserver_http_instance = NULL;
old_gamserver_inventory_instance = NULL;
old_gamserver_ugc_instance = NULL;
old_gamserver_apps_instance = NULL;