-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
1292 lines (1234 loc) · 53.6 KB
/
main.c
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
//===-- main.c - TEK Injector source code ---------------------------------===//
//
// Copyright (c) 2024 Nuclearist
// Part of TEK Injector, under the MIT License
// See https://github.com/Nuclearistt/tek-injector/blob/main/LICENSE for
// license information.
// SPDX-License-Identifier: MIT
//
//===----------------------------------------------------------------------===//
//
// Since PE image of this program is intended to be copied to another process
// the goal is to place everything it needs within the image, in particular
// have no DLL dependencies other than ntdll.dll and kernel32.dll which
// reside at the same address in all process, and minimize the use of CRT as
// most of its functions create or use context in heap outside of image.
// There are dependencies on advapi32.dll, shell32.dll and user32.dll, but
// they're only used on host side so don't cause any issues.
//
//===----------------------------------------------------------------------===//
#include <stdint.h>
// Exclude unnecessary APIs
#define WIN32_LEAN_AND_MEAN
#define NOGDICAPMASKS
#define NOVIRTUALKEYCODES
#define NOWINMESSAGES
#define NOWINSTYLES
#define NOSYSMETRICS
#define NOMENUS
#define NOICONS
#define NOKEYSTATES
#define NOSYSCOMMANDS
#define NORASTEROPS
#define NOSHOWWINDOW
#define OEMRESOURCE
#define NOATOM
#define NOCLIPBOARD
#define NOCOLOR
#define NOCTLMGR
#define NODRAWTEXT
#define NOGDI
#define NOKERNEL
#define NOMEMMGR
#define NOMETAFILE
#define NOMINMAX
#define NOMSG
#define NOOPENFILE
#define NOSCROLL
#define NOSERVICE
#define NOSOUND
#define NOTEXTMETRIC
#define NOWH
#define NOWINOFFSETS
#define NOCOMM
#define NOKANJI
#define NOHELP
#define NOPROFILER
#define NODEFERWINDOWPOS
#define NOMCX
#include <Windows.h>
#include <shellapi.h>
//===- TEK Injector error codes -------------------------------------------===//
enum error_code {
EC_SUCCESS = 0,
EC_MIN = -10,
// Injector error codes
IEC_VIRTUAL_PROTECT_FAILED,
IEC_DUPLICATE_TOKEN_FAILED,
IEC_SET_TOKEN_INF_FAILED,
IEC_CREATE_PROCESS_FAILED,
IEC_VIRTUAL_ALLOC_FAILED,
IEC_WRITE_PROC_MEM_FAILED,
IEC_SET_THREAD_CTX_FAILED,
// Game error codes
GEC_STEAM_API_INIT_FAILED,
GEC_EOS_AUTH_LOGIN_FAILED
};
static const wchar_t *const error_code_strings[] = {
L"Failed to change PE section protection",
L"Failed to duplicate process token",
L"Failed to set token information",
L"Failed to create game process",
L"Failed to allocate memory in game process",
L"Failed to write image to game process",
L"Failed to modify game thread context",
L"Steam API initialization failed",
L"Epic Games authentication failed"};
//===- Game-side functions (called inside game process) -------------------===//
//===--- vmn_stub methods (implemented in vm-stubs.s) ---------------------===//
extern void vm0_stub();
extern void vm1_stub();
extern void vm2_stub();
extern void vm3_stub();
extern void vm4_stub();
extern void vm5_stub();
extern void vm6_stub();
extern void vm7_stub();
extern void vm8_stub();
extern void vm9_stub();
extern void vm10_stub();
extern void vm11_stub();
extern void vm12_stub();
extern void vm13_stub();
extern void vm14_stub();
extern void vm15_stub();
extern void vm16_stub();
extern void vm17_stub();
extern void vm18_stub();
extern void vm19_stub();
extern void vm20_stub();
extern void vm21_stub();
extern void vm22_stub();
extern void vm23_stub();
extern void vm24_stub();
extern void vm25_stub();
extern void vm26_stub();
extern void vm27_stub();
extern void vm28_stub();
extern void vm29_stub();
extern void vm30_stub();
extern void vm31_stub();
extern void vm32_stub();
extern void vm33_stub();
extern void vm34_stub();
extern void vm35_stub();
extern void vm36_stub();
extern void vm37_stub();
//===--- Steam API method wrappers ----------------------------------------===//
struct cpp_interface_wrapper {
void *const *vtable; // Pointer to virtual method table
void *original_interface; // Read by vmn_stub methods
};
static uint64_t steam_id; // Steam ID of current user
//===----- ISteamApps -----------------------------------------------------===//
static void *isteam_apps_vtable[29];
static struct cpp_interface_wrapper isteam_apps_wrapper;
static bool return_true() { return true; }
static int asa_get_dlc_count() { return 6; }
static bool asa_get_dlc_data_by_index(struct cpp_interface_wrapper *_, int iDLC,
uint32_t *pAppID, bool *pbAvailable,
char *pchName) {
*pbAvailable = true;
switch (iDLC) {
case 0:
*pAppID = 2827030;
memcpy(pchName, "ARK: The Center Ascended",
sizeof("ARK: The Center Ascended"));
return true;
case 1:
*pAppID = 2849450;
memcpy(pchName, "ARK: Scorched Earth Ascended",
sizeof("ARK: Scorched Earth Ascended"));
return true;
case 2:
*pAppID = 2881150;
memcpy(pchName, "ARK: Bob's Tall Tales", sizeof("ARK: Bob's Tall Tales"));
return true;
case 3:
*pAppID = 2972680;
memcpy(pchName, "ARK Fantastic Tames - Pyromane", sizeof("ARK Fantastic Tames - Pyromane"));
return true;
case 4:
*pAppID = 3059650;
memcpy(pchName, "ARK: Aberration Ascended",
sizeof("ARK: Aberration Ascended"));
return true;
case 5:
*pAppID = 3282470;
memcpy(pchName, "ARK Fantastic Tames - Dreadmare",
sizeof("ARK Fantastic Tames - Dreadmare"));
return true;
default:
return false;
}
}
static uint64_t *get_app_owner(struct cpp_interface_wrapper *_,
uint64_t *steamId) {
*steamId = steam_id;
return steamId;
}
//===----- ISteamMatchmakingServers ---------------------------------------===//
struct MatchMakingKeyValuePair_t {
char m_szKey[256];
char m_szValue[256];
};
struct server_rules_callback_wrapper {
void *const *vtable; // Pointer to virtual method table
void *original_callback;
int query_handle; // Handle returned by ServerRules()
};
static void *server_rules_callback_wrapper_vtable[3];
static void *isteam_matchmaking_servers_vtable[17];
static struct cpp_interface_wrapper isteam_matchmaking_servers_wrapper;
static void rules_responded(struct server_rules_callback_wrapper *wrapper,
const char *pchRule, const char *pchValue) {
// If server reports that it has BattlEye or doesn't have TEK Wrapper, cancel
// the query
if ((!strcmp(pchRule, "SERVERUSESBATTLEYE_b") && pchValue[0] != 'f') ||
(!strcmp(pchRule, "SEARCHKEYWORDS_s") &&
strncmp(pchValue, "TEKWrapper", 10))) {
// Call CancelServerQuery on the original ISteamMatchmakingServers
((void (*)(void *, int))((*(
(void ***)isteam_matchmaking_servers_wrapper.original_interface))[16]))(
isteam_matchmaking_servers_wrapper.original_interface,
wrapper->query_handle);
// Call RulesFailedToRespond on original callback
((void (*)(void *))((*((void ***)wrapper->original_callback))[1]))(
wrapper->original_callback);
// Detach original callback so game won't receive any calls anymore
wrapper->original_callback = NULL;
} else if (wrapper->original_callback)
((void (*)(void *, const char *, const char *))(
(*((void ***)wrapper->original_callback))[0]))(
wrapper->original_callback, pchRule, pchValue);
}
static void
rules_failed_to_respond(struct server_rules_callback_wrapper *wrapper) {
// Call RulesFailedToRespond on original callback
if (wrapper->original_callback)
((void (*)(void *))((*((void ***)wrapper->original_callback))[1]))(
wrapper->original_callback);
// Free the memory used for wrapper object
HeapFree(GetProcessHeap(), 0, wrapper);
}
static void
rules_refresh_complete(struct server_rules_callback_wrapper *wrapper) {
// Call RulesRefreshComplete on original callback
if (wrapper->original_callback)
((void (*)(void *))((*((void ***)wrapper->original_callback))[2]))(
wrapper->original_callback);
// Free the memory used for wrapper object
HeapFree(GetProcessHeap(), 0, wrapper);
}
static void *
request_internet_server_list(struct cpp_interface_wrapper *wrapper,
uint32_t iApp,
struct MatchMakingKeyValuePair_t **ppchFilters,
uint32_t nFilters, void *pRequestServersResponse) {
char *cur = (*ppchFilters)[nFilters - 1].m_szValue;
// Make cur point to the terminating null
while (*cur)
++cur;
memcpy(cur, ",SERVERUSESBATTLEYE_b:false,TEKWrapper:1",
sizeof(",SERVERUSESBATTLEYE_b:false,TEKWrapper:1"));
return ((void *(*)(void *, uint32_t, struct MatchMakingKeyValuePair_t **,
uint32_t,
void *))((*((void ***)wrapper->original_interface))[0]))(
wrapper->original_interface, iApp, ppchFilters, nFilters,
pRequestServersResponse);
}
static int server_rules(struct cpp_interface_wrapper *wrapper, uint32_t unIP,
uint16_t usPort, void *pRequestServersResponse) {
// Create a callback wrapper for this query
struct server_rules_callback_wrapper *const callbackWrapper = HeapAlloc(
GetProcessHeap(), 0, sizeof(struct server_rules_callback_wrapper));
callbackWrapper->vtable = server_rules_callback_wrapper_vtable;
callbackWrapper->original_callback = pRequestServersResponse;
int query = ((int (*)(void *, uint32_t, uint16_t, void *))(
(*((void ***)wrapper->original_interface))[15]))(
wrapper->original_interface, unIP, usPort, callbackWrapper);
callbackWrapper->query_handle = query;
return query;
}
//===----- ISteamUGC ------------------------------------------------------===//
static void *isteam_ugc_vtable[31];
static struct cpp_interface_wrapper isteam_ugc_wrapper;
static uint32_t get_num_subscribed_items() {
// Search the Mods directory in game root
WIN32_FIND_DATAW findData;
const HANDLE find = FindFirstFileExW(
L"..\\..\\..\\Mods\\*", FindExInfoBasic, &findData,
FindExSearchLimitToDirectories, NULL, FIND_FIRST_EX_LARGE_FETCH);
if (find == INVALID_HANDLE_VALUE)
return 0;
DWORD numInstalledMods = 0;
FindNextFileW(find, &findData); // Skip .. entry
while (FindNextFileW(find, &findData)) {
// Only cound directories with IDs as names
bool validNumber = true;
for (const WCHAR *i = findData.cFileName; *i; ++i)
if (*i < L'0' || *i > L'9') {
validNumber = false;
break;
}
if (validNumber)
numInstalledMods++;
}
FindClose(find);
return numInstalledMods;
}
static uint32_t get_subscribed_items(struct cpp_interface_wrapper *_,
uint64_t *pvecPublishedFileID,
uint32_t cMaxEntries) {
// Search the Mods directory in game root
WIN32_FIND_DATAW findData;
const HANDLE find = FindFirstFileExW(
L"..\\..\\..\\Mods\\*", FindExInfoBasic, &findData,
FindExSearchLimitToDirectories, NULL, FIND_FIRST_EX_LARGE_FETCH);
if (find == INVALID_HANDLE_VALUE)
return 0;
FindNextFileW(find, &findData); // Skip .. entry
while (FindNextFileW(find, &findData)) {
uint64_t id = 0;
for (const WCHAR *i = findData.cFileName; *i; ++i) {
const uint64_t digit = (uint64_t)*i - L'0';
if (digit > 9) {
id = 0;
break;
}
id = id * 10 + digit;
}
if (id)
*pvecPublishedFileID++ = id;
}
FindClose(find);
return cMaxEntries;
}
static bool get_item_install_info(struct cpp_interface_wrapper *_,
uint64_t nPublishedFileID,
uint64_t *punSizeOnDisk, char *pchFolder,
uint32_t cchFolderSize, bool *pbLegacyItem) {
*punSizeOnDisk = 0; // This is not used by the game so not worth computing
*pbLegacyItem = false;
WCHAR pathBuffer[MAX_PATH] = L"..\\..\\..\\Mods\\";
WCHAR numberBuffer[20];
numberBuffer[19] = L'\0';
WCHAR *const numberBufferEnd = numberBuffer + 20;
WCHAR *i = numberBufferEnd - 1;
while (nPublishedFileID) {
*--i = L'0' + (nPublishedFileID % 10);
nPublishedFileID /= 10;
}
memcpy(pathBuffer + 14, i, (numberBufferEnd - i) * sizeof(WCHAR));
if (GetFileAttributesW(pathBuffer) == INVALID_FILE_ATTRIBUTES) {
// Mod directory doesn't exist
*pchFolder = '\0';
return false;
} else {
// Why not just use GetFileAttributesA? It only supports ASCII and
// non-latin characters in path break it.
WideCharToMultiByte(CP_UTF8, 0, pathBuffer, -1, pchFolder, cchFolderSize,
NULL, NULL);
return true;
}
}
//===----- ISteamUtils ----------------------------------------------------===//
static void *isteam_utils_vtable[38];
static struct cpp_interface_wrapper isteam_utils_wrapper;
static uint32_t asa_get_app_id() { return 2399830; }
static uint32_t ase_get_app_id() { return 346110; }
//===--- steam_api64.dll function wrappers --------------------------------===//
// Sets up ISteamApps wrappers in ASE
static void *(*SteamApps)();
static void *SteamApps_wrapper() {
if (!isteam_apps_wrapper.original_interface) {
isteam_apps_vtable[0] = return_true; // BIsSubscribed
isteam_apps_vtable[1] = vm1_stub; // BIsLowViolence
isteam_apps_vtable[2] = vm2_stub; // BIsCybercafe
isteam_apps_vtable[3] = vm3_stub; // BIsVACBanned
isteam_apps_vtable[4] = vm4_stub; // GetCurrentGameLanguage
isteam_apps_vtable[5] = vm5_stub; // GetAvailableGameLanguages
isteam_apps_vtable[6] = return_true; // BIsSubscribedApp
isteam_apps_vtable[7] = return_true; // BIsDlcInstalled
isteam_apps_vtable[8] = vm8_stub; // GetEarliestPurchaseUnixTime
isteam_apps_vtable[9] = vm9_stub; // BIsSubscribedFromFreeWeekend
isteam_apps_vtable[10] = vm10_stub; // GetDLCCount
isteam_apps_vtable[11] = vm11_stub; // BGetDLCDataByIndex
isteam_apps_vtable[12] = vm12_stub; // InstallDLC
isteam_apps_vtable[13] = vm13_stub; // UninstallDLC
isteam_apps_vtable[14] = vm14_stub; // RequestAppProofOfPurchaseKey
isteam_apps_vtable[15] = vm15_stub; // GetCurrentBetaName
isteam_apps_vtable[16] = vm16_stub; // MarkContentCorrupt
isteam_apps_vtable[17] = vm17_stub; // GetInstalledDepots
isteam_apps_vtable[18] = vm18_stub; // GetAppInstallDir
isteam_apps_vtable[19] = vm19_stub; // BIsAppInstalled
isteam_apps_vtable[20] = get_app_owner; // GetAppOwner
isteam_apps_vtable[21] = vm21_stub; // GetLaunchQueryParam
isteam_apps_vtable[22] = vm22_stub; // GetDlcDownloadProgress
isteam_apps_vtable[23] = vm23_stub; // GetAppBuildId
isteam_apps_wrapper.vtable = isteam_apps_vtable;
isteam_apps_wrapper.original_interface = SteamApps();
}
return &isteam_apps_wrapper;
}
// Sets up ISteamMatchmakingServers wrappers in ASE
static void *(*SteamMatchmakingServers)();
static void *SteamMatchmakingServers_wrapper() {
if (!isteam_matchmaking_servers_wrapper.original_interface) {
server_rules_callback_wrapper_vtable[0] = rules_responded;
server_rules_callback_wrapper_vtable[1] = rules_failed_to_respond;
server_rules_callback_wrapper_vtable[2] = rules_refresh_complete;
isteam_matchmaking_servers_vtable[0] =
request_internet_server_list; // RequestInternetServerList
isteam_matchmaking_servers_vtable[1] = vm1_stub; // RequestLANServerList
isteam_matchmaking_servers_vtable[2] = vm2_stub; // RequestFriendsServerList
isteam_matchmaking_servers_vtable[3] =
vm3_stub; // RequestFavoritesServerList
isteam_matchmaking_servers_vtable[4] = vm4_stub; // RequestHistoryServerList
isteam_matchmaking_servers_vtable[5] =
vm5_stub; // RequestSpectatorServerList
isteam_matchmaking_servers_vtable[6] = vm6_stub; // ReleaseRequest
isteam_matchmaking_servers_vtable[7] = vm7_stub; // GetServerDetails
isteam_matchmaking_servers_vtable[8] = vm8_stub; // CancelQuery
isteam_matchmaking_servers_vtable[9] = vm9_stub; // RefreshQuery
isteam_matchmaking_servers_vtable[10] = vm10_stub; // IsRefreshing
isteam_matchmaking_servers_vtable[11] = vm11_stub; // GetServerCount
isteam_matchmaking_servers_vtable[12] = vm12_stub; // RefreshServer
isteam_matchmaking_servers_vtable[13] = vm13_stub; // PingServer
isteam_matchmaking_servers_vtable[14] = vm14_stub; // PlayerDetails
isteam_matchmaking_servers_vtable[15] = server_rules; // ServerRules
isteam_matchmaking_servers_vtable[16] = vm16_stub; // CancelServerQuery
isteam_matchmaking_servers_wrapper.vtable =
isteam_matchmaking_servers_vtable;
isteam_matchmaking_servers_wrapper.original_interface =
SteamMatchmakingServers();
}
return &isteam_matchmaking_servers_wrapper;
}
// Sets up ISteamUGC wrappers in ASE
static void *(*SteamUGC)();
static void *SteamUGC_wrapper() {
if (!isteam_ugc_wrapper.original_interface) {
isteam_ugc_vtable[0] = vm0_stub; // CreateQueryUserUGCRequest
isteam_ugc_vtable[1] = vm1_stub; // CreateQueryAllUGCRequest
isteam_ugc_vtable[2] = vm2_stub; // SendQueryUGCRequest
isteam_ugc_vtable[3] = vm3_stub; // GetQueryUGCResult
isteam_ugc_vtable[4] = vm4_stub; // ReleaseQueryUGCRequest
isteam_ugc_vtable[5] = vm5_stub; // AddRequiredTag
isteam_ugc_vtable[6] = vm6_stub; // AddExcludedTag
isteam_ugc_vtable[7] = vm7_stub; // SetReturnLongDescription
isteam_ugc_vtable[8] = vm8_stub; // SetReturnTotalOnly
isteam_ugc_vtable[9] = vm9_stub; // SetAllowCachedResponse
isteam_ugc_vtable[10] = vm10_stub; // SetCloudFileNameFilter
isteam_ugc_vtable[11] = vm11_stub; // SetMatchAnyTag
isteam_ugc_vtable[12] = vm12_stub; // SetSearchText
isteam_ugc_vtable[13] = vm13_stub; // SetRankedByTrendDays
isteam_ugc_vtable[14] = vm14_stub; // RequestUGCDetails
isteam_ugc_vtable[15] = vm15_stub; // CreateItem
isteam_ugc_vtable[16] = vm16_stub; // StartItemUpdate
isteam_ugc_vtable[17] = vm17_stub; // SetItemTitle
isteam_ugc_vtable[18] = vm18_stub; // SetItemDescription
isteam_ugc_vtable[19] = vm19_stub; // SetItemVisibility
isteam_ugc_vtable[20] = vm20_stub; // SetItemTags
isteam_ugc_vtable[21] = vm21_stub; // SetItemContent
isteam_ugc_vtable[22] = vm22_stub; // SetItemPreview
isteam_ugc_vtable[23] = vm23_stub; // SubmitItemUpdate
isteam_ugc_vtable[24] = vm24_stub; // GetItemUpdateProgress
isteam_ugc_vtable[25] = vm25_stub; // SubscribeItem
isteam_ugc_vtable[26] = vm26_stub; // UnsubscribeItem
isteam_ugc_vtable[27] = get_num_subscribed_items; // GetNumSubscribedItems
isteam_ugc_vtable[28] = get_subscribed_items; // GetSubscribedItems
isteam_ugc_vtable[29] = get_item_install_info; // GetItemInstallInfo
isteam_ugc_vtable[30] = vm30_stub; // GetItemUpdateInfo
isteam_ugc_wrapper.vtable = isteam_ugc_vtable;
isteam_ugc_wrapper.original_interface = SteamUGC();
}
return &isteam_ugc_wrapper;
}
// Sets up ISteamUtils wrappers in ASE
static void *(*SteamUtils)();
static void *SteamUtils_wrapper() {
if (!isteam_utils_wrapper.original_interface) {
isteam_utils_vtable[0] = vm0_stub; // GetSecondsSinceAppActive
isteam_utils_vtable[1] = vm1_stub; // GetSecondsSinceComputerActive
isteam_utils_vtable[2] = vm2_stub; // GetConnectedUniverse
isteam_utils_vtable[3] = vm3_stub; // GetServerRealTime
isteam_utils_vtable[4] = vm4_stub; // GetIPCountry
isteam_utils_vtable[5] = vm5_stub; // GetImageSize
isteam_utils_vtable[6] = vm6_stub; // GetImageRGBA
isteam_utils_vtable[7] = vm7_stub; // GetCSERIPPort
isteam_utils_vtable[8] = vm8_stub; // GetCurrentBatteryPower
isteam_utils_vtable[9] = ase_get_app_id; // GetAppID
isteam_utils_vtable[10] = vm10_stub; // SetOverlayNotificationPosition
isteam_utils_vtable[11] = vm11_stub; // IsAPICallCompleted
isteam_utils_vtable[12] = vm12_stub; // GetAPICallFailureReason
isteam_utils_vtable[13] = vm13_stub; // GetAPICallResult
isteam_utils_vtable[14] = vm14_stub; // RunFrame
isteam_utils_vtable[15] = vm15_stub; // GetIPCCallCount
isteam_utils_vtable[16] = vm16_stub; // SetWarningMessageHook
isteam_utils_vtable[17] = vm17_stub; // IsOverlayEnabled
isteam_utils_vtable[18] = vm18_stub; // BOverlayNeedsPresent
isteam_utils_vtable[19] = vm19_stub; // CheckFileSignature
isteam_utils_vtable[20] = vm20_stub; // ShowGamepadTextInput
isteam_utils_vtable[21] = vm21_stub; // GetEnteredGamepadTextLength
isteam_utils_vtable[22] = vm22_stub; // GetEnteredGamepadTextInput
isteam_utils_vtable[23] = vm23_stub; // GetSteamUILanguage
isteam_utils_vtable[24] = vm24_stub; // IsSteamRunningInVR
isteam_utils_wrapper.vtable = isteam_utils_vtable;
isteam_utils_wrapper.original_interface = SteamUtils();
}
return &isteam_utils_wrapper;
}
// Sets up interface wrappers in ASA, the only function that provides access
// to Steam API interfaces in its newer versions
static void *(*SteamInternal_FindOrCreateUserInterface)(int, const char *);
static void *
SteamInternal_FindOrCreateUserInterface_wrapper(int hSteamUser,
const char *pszVersion) {
void *interface =
SteamInternal_FindOrCreateUserInterface(hSteamUser, pszVersion);
if (!strcmp(pszVersion, "STEAMAPPS_INTERFACE_VERSION008")) {
isteam_apps_vtable[0] = return_true; // BIsSubscribed
isteam_apps_vtable[1] = vm1_stub; // BIsLowViolence
isteam_apps_vtable[2] = vm2_stub; // BIsCybercafe
isteam_apps_vtable[3] = vm3_stub; // BIsVACBanned
isteam_apps_vtable[4] = vm4_stub; // GetCurrentGameLanguage
isteam_apps_vtable[5] = vm5_stub; // GetAvailableGameLanguages
isteam_apps_vtable[6] = return_true; // BIsSubscribedApp
isteam_apps_vtable[7] = return_true; // BIsDlcInstalled
isteam_apps_vtable[8] = vm8_stub; // GetEarliestPurchaseUnixTime
isteam_apps_vtable[9] = vm9_stub; // BIsSubscribedFromFreeWeekend
isteam_apps_vtable[10] = asa_get_dlc_count; // GetDLCCount
isteam_apps_vtable[11] = asa_get_dlc_data_by_index; // BGetDLCDataByIndex
isteam_apps_vtable[12] = vm12_stub; // InstallDLC
isteam_apps_vtable[13] = vm13_stub; // UninstallDLC
isteam_apps_vtable[14] = vm14_stub; // RequestAppProofOfPurchaseKey
isteam_apps_vtable[15] = vm15_stub; // GetCurrentBetaName
isteam_apps_vtable[16] = vm16_stub; // MarkContentCorrupt
isteam_apps_vtable[17] = vm17_stub; // GetInstalledDepots
isteam_apps_vtable[18] = vm18_stub; // GetAppInstallDir
isteam_apps_vtable[19] = vm19_stub; // BIsAppInstalled
isteam_apps_vtable[20] = get_app_owner; // GetAppOwner
isteam_apps_vtable[21] = vm21_stub; // GetLaunchQueryParam
isteam_apps_vtable[22] = vm22_stub; // GetDlcDownloadProgress
isteam_apps_vtable[23] = vm23_stub; // GetAppBuildId
isteam_apps_vtable[24] = vm24_stub; // RequestAllProofOfPurchaseKeys
isteam_apps_vtable[25] = vm25_stub; // GetFileDetails
isteam_apps_vtable[26] = vm26_stub; // GetLaunchCommandLine
isteam_apps_vtable[27] = vm27_stub; // BIsSubscribedFromFamilySharing
isteam_apps_vtable[28] = vm28_stub; // BIsTimedTrial
isteam_apps_wrapper.vtable = isteam_apps_vtable;
isteam_apps_wrapper.original_interface = interface;
return &isteam_apps_wrapper;
} else if (!strcmp(pszVersion, "SteamUser021")) {
// This interface is only needed to get user Steam ID
((uint64_t * (*)(void *, uint64_t *))((*((void ***)interface))[2]))(
interface, &steam_id);
} else if (!strcmp(pszVersion, "SteamUtils010")) {
isteam_utils_vtable[0] = vm0_stub; // GetSecondsSinceAppActive
isteam_utils_vtable[1] = vm1_stub; // GetSecondsSinceComputerActive
isteam_utils_vtable[2] = vm2_stub; // GetConnectedUniverse
isteam_utils_vtable[3] = vm3_stub; // GetServerRealTime
isteam_utils_vtable[4] = vm4_stub; // GetIPCountry
isteam_utils_vtable[5] = vm5_stub; // GetImageSize
isteam_utils_vtable[6] = vm6_stub; // GetImageRGBA
isteam_utils_vtable[7] = vm7_stub; // GetCSERIPPort
isteam_utils_vtable[8] = vm8_stub; // GetCurrentBatteryPower
isteam_utils_vtable[9] = asa_get_app_id; // GetAppID
isteam_utils_vtable[10] = vm10_stub; // SetOverlayNotificationPosition
isteam_utils_vtable[11] = vm11_stub; // IsAPICallCompleted
isteam_utils_vtable[12] = vm12_stub; // GetAPICallFailureReason
isteam_utils_vtable[13] = vm13_stub; // GetAPICallResult
isteam_utils_vtable[14] = vm14_stub; // RunFrame
isteam_utils_vtable[15] = vm15_stub; // GetIPCCallCount
isteam_utils_vtable[16] = vm16_stub; // SetWarningMessageHook
isteam_utils_vtable[17] = vm17_stub; // IsOverlayEnabled
isteam_utils_vtable[18] = vm18_stub; // BOverlayNeedsPresent
isteam_utils_vtable[19] = vm19_stub; // CheckFileSignature
isteam_utils_vtable[20] = vm20_stub; // ShowGamepadTextInput
isteam_utils_vtable[21] = vm21_stub; // GetEnteredGamepadTextLength
isteam_utils_vtable[22] = vm22_stub; // GetEnteredGamepadTextInput
isteam_utils_vtable[23] = vm23_stub; // GetSteamUILanguage
isteam_utils_vtable[24] = vm24_stub; // IsSteamRunningInVR
isteam_utils_vtable[25] = vm25_stub; // SetOverlayNotificationInset
isteam_utils_vtable[26] = vm26_stub; // IsSteamInBigPictureMode
isteam_utils_vtable[27] = vm27_stub; // StartVRDashboard
isteam_utils_vtable[28] = vm28_stub; // IsVRHeadsetStreamingEnabled
isteam_utils_vtable[29] = vm29_stub; // SetVRHeadsetStreamingEnabled
isteam_utils_vtable[30] = vm30_stub; // IsSteamChinaLauncher
isteam_utils_vtable[31] = vm31_stub; // InitFilterText
isteam_utils_vtable[32] = vm32_stub; // FilterText
isteam_utils_vtable[33] = vm33_stub; // GetIPv6ConnectivityState
isteam_utils_vtable[34] = vm34_stub; // IsSteamRunningOnSteamDeck
isteam_utils_vtable[35] = vm35_stub; // ShowFloatingGamepadTextInput
isteam_utils_vtable[36] = vm36_stub; // SetGameLauncherMode
isteam_utils_vtable[37] = vm37_stub; // DismissFloatingGamepadTextInput
isteam_utils_wrapper.vtable = isteam_utils_vtable;
isteam_utils_wrapper.original_interface = interface;
return &isteam_utils_wrapper;
}
return interface;
}
//===--- EOS SDK types ----------------------------------------------------===//
enum EOS_EAuthScopeFlags {
EOS_AS_NoFlags = 0x0,
EOS_AS_BasicProfile = 0x1,
EOS_AS_FriendsList = 0x2,
EOS_AS_Presence = 0x4,
EOS_AS_FriendsManagement = 0x8,
EOS_AS_Email = 0x10,
EOS_AS_Country = 0x20
};
enum EOS_EExternalAccountType {
EOS_EAT_EPIC,
EOS_EAT_STEAM,
EOS_EAT_PSN,
EOS_EAT_XBL,
EOS_EAT_DISCORD,
EOS_EAT_GOG,
EOS_EAT_NINTENDO,
EOS_EAT_UPLAY,
EOS_EAT_OPENID,
EOS_EAT_APPLE,
EOS_EAT_GOOGLE,
EOS_EAT_OCULUS,
EOS_EAT_ITCHIO,
EOS_EAT_AMAZON
};
enum EOS_EExternalCredentialType {
EOS_ECT_EPIC,
EOS_ECT_STEAM_APP_TICKET,
EOS_ECT_PSN_ID_TOKEN,
EOS_ECT_XBL_XSTS_TOKEN,
EOS_ECT_DISCORD_ACCESS_TOKEN,
EOS_ECT_GOG_SESSION_TICKET,
EOS_ECT_NINTENDO_ID_TOKEN,
EOS_ECT_NINTENDO_NSA_ID_TOKEN,
EOS_ECT_UPLAY_ACCESS_TOKEN,
EOS_ECT_OPENID_ACCESS_TOKEN,
EOS_ECT_DEVICEID_ACCESS_TOKEN,
EOS_ECT_APPLE_ID_TOKEN,
EOS_ECT_GOOGLE_ID_TOKEN,
EOS_ECT_OCULUS_USERID_NONCE,
EOS_ECT_ITCHIO_JWT,
EOS_ECT_ITCHIO_KEY,
EOS_ECT_EPIC_ID_TOKEN,
EOS_ECT_AMAZON_ACCESS_TOKEN,
EOS_ECT_STEAM_SESSION_TICKET
};
enum EOS_ELoginCredentialType {
EOS_LCT_Password,
EOS_LCT_ExchangeCode,
EOS_LCT_PersistentAuth,
EOS_LCT_DeviceCode,
EOS_LCT_Developer,
EOS_LCT_RefreshToken,
EOS_LCT_AccountPortal,
EOS_LCT_ExternalAuth
};
struct EOS_Auth_CopyIdTokenOptions {
int32_t ApiVersion;
void *AccountId;
};
struct EOS_Auth_Credentials {
int32_t ApiVersion;
const char *Id;
const char *Token;
enum EOS_ELoginCredentialType Type;
void *SystemAuthCredentialsOptions;
enum EOS_EExternalCredentialType ExternalType;
};
struct EOS_Auth_IdToken {
int32_t ApiVersion;
void *AccountId;
const char *JsonWebToken;
};
struct EOS_Auth_LoginCallbackInfo {
int ResultCode;
void *ClientData;
void *LocalUserId;
const void *PinGrantInfo;
void *ContinuanceToken;
const void *AccountFeatureRestrictedInfo;
void *SelectedAccountId;
};
struct EOS_Auth_LoginOptions {
int32_t ApiVersion;
const struct EOS_Auth_Credentials *Credentials;
enum EOS_EAuthScopeFlags ScopeFlags;
};
struct EOS_Connect_Credentials {
int32_t ApiVersion;
const char *Token;
enum EOS_EExternalCredentialType Type;
};
struct EOS_Connect_ExternalAccountInfo {
int32_t ApiVersion;
void *ProductUserId;
const char *DisplayName;
const char *AccountId;
enum EOS_EExternalAccountType AccountIdType;
int64_t LastLoginTime;
};
struct EOS_Connect_LoginOptions {
int32_t ApiVersion;
const struct EOS_Connect_Credentials *Credentials;
const void *UserLoginInfo;
};
//===--- EOSSDK-Win64-Shipping.dll function wrappers ----------------------===//
// Used by eos_auth_login_callback to track its state
static bool eos_persistent_auth_failed = false;
// Used by eos_auth_login_callback
static void *restrict auth_interface;
// Stores the token between EOS_Platform_Create and EOS_Connect_Login calls
static struct EOS_Auth_IdToken *eos_auth_token;
static int (*EOS_Auth_CopyIdToken)(
void *Handle, const struct EOS_Auth_CopyIdTokenOptions *Options,
struct EOS_Auth_IdToken **OutIdToken);
static void (*EOS_Auth_Login)(void *Handle,
const struct EOS_Auth_LoginOptions *Options,
void *ClientData,
void (*const CompletionDelegate)(
const struct EOS_Auth_LoginCallbackInfo *));
static void *(*EOS_Platform_GetAuthInterface)(void *Handle);
static void *(*EOS_Platform_Tick)(void *Handle);
static int (*EOS_Connect_CopyProductUserInfo)(
void *Handle, const void *Options,
struct EOS_Connect_ExternalAccountInfo **OutExternalAccountInfo);
static int EOS_Connect_CopyProductUserInfo_wrapper(
void *Handle, const void *Options,
struct EOS_Connect_ExternalAccountInfo **OutExternalAccountInfo) {
int result =
EOS_Connect_CopyProductUserInfo(Handle, Options, OutExternalAccountInfo);
if (!result) {
// Set account type to Steam so stuff that relies on it doesn't break
struct EOS_Connect_ExternalAccountInfo *const accountInfo =
*OutExternalAccountInfo;
accountInfo->AccountIdType = EOS_EAT_STEAM;
accountInfo->AccountId = NULL;
}
return result;
}
static void (*EOS_Connect_Login)(void *Handle,
const struct EOS_Connect_LoginOptions *Options,
void *ClientData,
const void *CompletionDelegate);
static void
EOS_Connect_Login_wrapper(void *Handle,
const struct EOS_Connect_LoginOptions *Options,
void *ClientData, const void *CompletionDelegate) {
// Replace Steam session ticket with our Epic ID token
struct EOS_Connect_Credentials *credentials =
(struct EOS_Connect_Credentials *)Options->Credentials;
credentials->Type = EOS_ECT_EPIC_ID_TOKEN;
credentials->Token = eos_auth_token->JsonWebToken;
EOS_Connect_Login(Handle, Options, ClientData, CompletionDelegate);
}
static void
eos_auth_login_callback(const struct EOS_Auth_LoginCallbackInfo *Data) {
if (!Data->ResultCode)
*((void **)Data->ClientData) = Data->LocalUserId; // Login succeeded
else if (eos_persistent_auth_failed)
ExitProcess(GEC_EOS_AUTH_LOGIN_FAILED); // Both auth types failed
else {
// Retry login with EOS_LCT_AccountPortal
const struct EOS_Auth_Credentials credentials = {
3, NULL, NULL, EOS_LCT_AccountPortal, NULL, 0};
const struct EOS_Auth_LoginOptions options = {2, &credentials,
EOS_AS_NoFlags};
EOS_Auth_Login(auth_interface, &options, Data->ClientData,
eos_auth_login_callback);
}
}
// This is one of the first functions called in EOS API so it can be used for
// early Epic Games authenticaiton
static void *(*EOS_Platform_Create)(const void *Options);
static void *EOS_Platform_Create_wrapper(const void *Options) {
void *const platform = EOS_Platform_Create(Options);
auth_interface = EOS_Platform_GetAuthInterface(platform);
// Try to login with EOS_LCT_PersistentAuth first
const struct EOS_Auth_Credentials credentials = {
3, NULL, NULL, EOS_LCT_PersistentAuth, NULL, 0};
const struct EOS_Auth_LoginOptions loginOptions = {2, &credentials,
EOS_AS_NoFlags};
struct EOS_Auth_CopyIdTokenOptions copyTokenOptions = {1, NULL};
EOS_Auth_Login(auth_interface, &loginOptions, ©TokenOptions.AccountId,
eos_auth_login_callback);
// Wait for login to complete
while (!copyTokenOptions.AccountId) {
EOS_Platform_Tick(platform);
SwitchToThread(); // Yield execution to another thread to skip time without
// excessive CPU usage
}
EOS_Auth_CopyIdToken(auth_interface, ©TokenOptions, &eos_auth_token);
return platform;
}
//===--- Process entry point wrappers -------------------------------------===//
// Substitutes entry point for ArkAscended.exe
static void __declspec(noreturn)
asa_entry(void __declspec(noreturn) (*entryPoint)(DWORD64)) {
// Step 1: load steam_api64.dll, find its IAT and call SteamAPI_Init
// Get image headers
const uint8_t *const moduleBase = (const uint8_t *)GetModuleHandleW(NULL);
const IMAGE_NT_HEADERS64 *const ntHeaders =
(const IMAGE_NT_HEADERS64
*)(moduleBase + ((const IMAGE_DOS_HEADER *)moduleBase)->e_lfanew);
const IMAGE_DELAYLOAD_DESCRIPTOR *const delayDescBase =
(const IMAGE_DELAYLOAD_DESCRIPTOR
*)(moduleBase +
ntHeaders->OptionalHeader
.DataDirectory[IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT]
.VirtualAddress);
const IMAGE_DELAYLOAD_DESCRIPTOR *delayDesc = delayDescBase;
// Find delay import descriptor for steam_api64.dll
while (strcmp((const char *)(moduleBase + delayDesc->DllNameRVA),
"steam_api64.dll"))
delayDesc++;
// Load the DLL explicitly, delay import loader is not aware of this relative
// path, then write the module handle to descriptor
const HMODULE steamApiModule =
LoadLibraryW(L"..\\..\\.."
L"\\Engine\\Binaries\\ThirdParty\\Steamworks\\Steamv153\\Win"
L"64\\steam_api64.dll");
*((HMODULE *)(moduleBase + delayDesc->ModuleHandleRVA)) = steamApiModule;
// Initialize Steam API
if (!((bool (*const)())GetProcAddress(steamApiModule, "SteamAPI_Init"))())
ExitProcess(GEC_STEAM_API_INIT_FAILED);
// Step 2: setup SteamInternal_FindOrCreateUserInterface wrapper
SteamInternal_FindOrCreateUserInterface =
(void *(*)(int, const char *))GetProcAddress(
steamApiModule, "SteamInternal_FindOrCreateUserInterface");
// Search import name table for SteamInternal_FindOrCreateUserInterface
const uint64_t *nameImportsBase =
(const uint64_t *)(moduleBase + delayDesc->ImportNameTableRVA);
uint32_t index = 0;
while (strcmp(
((const IMAGE_IMPORT_BY_NAME *)(moduleBase + nameImportsBase[index]))
->Name,
"SteamInternal_FindOrCreateUserInterface"))
index++;
// Use the index to get function pointer from IAT and write wrapper address
((void **)(moduleBase + delayDesc->ImportAddressTableRVA))[index] =
SteamInternal_FindOrCreateUserInterface_wrapper;
// Step 3: setup EOS SDK wrappers for Epic Games authentication if necessary
// GetEnvironmentVariableA returns 4 when app ID is 480 (3 characters + null)
if (GetEnvironmentVariableA("GameAppId", NULL, 0) == 4) {
// Find delay import descriptor for EOSSDK-Win64-Shipping.dll
delayDesc = delayDescBase;
while (strcmp((const char *)(moduleBase + delayDesc->DllNameRVA),
"EOSSDK-Win64-Shipping.dll"))
delayDesc++;
// Load the DLL explicitly, delay import loader is not aware of this
// relative path, then write the module handle to descriptor
const HMODULE eosSdkModule =
LoadLibraryW(L"RedpointEOS\\EOSSDK-Win64-Shipping.dll");
*((HMODULE *)(moduleBase + delayDesc->ModuleHandleRVA)) = eosSdkModule;
// Get all necessary function addresses
EOS_Auth_CopyIdToken = (int (*)(
void *, const struct EOS_Auth_CopyIdTokenOptions *,
struct EOS_Auth_IdToken **))GetProcAddress(eosSdkModule,
"EOS_Auth_CopyIdToken");
EOS_Auth_Login =
(void (*)(void *, const struct EOS_Auth_LoginOptions *, void *,
void (*const)(const struct EOS_Auth_LoginCallbackInfo *)))
GetProcAddress(eosSdkModule, "EOS_Auth_Login");
EOS_Connect_CopyProductUserInfo = (int (*)(
void *, const void *, struct EOS_Connect_ExternalAccountInfo **))
GetProcAddress(eosSdkModule, "EOS_Connect_CopyProductUserInfo");
EOS_Connect_Login =
(void (*)(void *, const struct EOS_Connect_LoginOptions *, void *,
const void *))GetProcAddress(eosSdkModule,
"EOS_Connect_Login");
EOS_Platform_Create = (void *(*)(const void *))GetProcAddress(
eosSdkModule, "EOS_Platform_Create");
EOS_Platform_GetAuthInterface = (void *(*)(void *))GetProcAddress(
eosSdkModule, "EOS_Platform_GetAuthInterface");
EOS_Platform_Tick =
(void *(*)(void *))GetProcAddress(eosSdkModule, "EOS_Platform_Tick");
// Search import name table for EOS_Connect_CopyProductUserInfo
nameImportsBase =
(const uint64_t *)(moduleBase + delayDesc->ImportNameTableRVA);
index = 0;
while (strcmp(
((const IMAGE_IMPORT_BY_NAME *)(moduleBase + nameImportsBase[index]))
->Name,
"EOS_Connect_CopyProductUserInfo"))
index++;
// Use the index to get function pointer from IAT and write wrapper address
((void **)(moduleBase + delayDesc->ImportAddressTableRVA))[index] =
EOS_Connect_CopyProductUserInfo_wrapper;
// Search import name table for EOS_Connect_Login
index = 0;
while (strcmp(
((const IMAGE_IMPORT_BY_NAME *)(moduleBase + nameImportsBase[index]))
->Name,
"EOS_Connect_Login"))
index++;
// Use the index to get function pointer from IAT and write wrapper address
((void **)(moduleBase + delayDesc->ImportAddressTableRVA))[index] =
EOS_Connect_Login_wrapper;
// Search import name table for EOS_Platform_Create
index = 0;
while (strcmp(
((const IMAGE_IMPORT_BY_NAME *)(moduleBase + nameImportsBase[index]))
->Name,
"EOS_Platform_Create"))
index++;
// Use the index to get function pointer from IAT and write wrapper address
((void **)(moduleBase + delayDesc->ImportAddressTableRVA))[index] =
EOS_Platform_Create_wrapper;
}
// Pass execution to actual entry point as if nothing happened
entryPoint(__readgsqword(0x60)); // Set PEB as the argument
}
// Substitutes entry point for ShooterGame.exe
static void __declspec(noreturn)
ase_entry(void __declspec(noreturn) (*entryPoint)(DWORD64)) {
// Step 1: load steam_api64.dll, find its IAT and call SteamAPI_Init
// Get image headers
const uint8_t *const moduleBase = (const uint8_t *)GetModuleHandleW(NULL);
const IMAGE_NT_HEADERS64 *const ntHeaders =
(const IMAGE_NT_HEADERS64
*)(moduleBase + ((const IMAGE_DOS_HEADER *)moduleBase)->e_lfanew);
const IMAGE_DELAYLOAD_DESCRIPTOR *const delayDescBase =
(const IMAGE_DELAYLOAD_DESCRIPTOR
*)(moduleBase +
ntHeaders->OptionalHeader
.DataDirectory[IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT]
.VirtualAddress);
const IMAGE_DELAYLOAD_DESCRIPTOR *delayDesc = delayDescBase;
// Find delay import descriptor for steam_api64.dll
while (strcmp((const char *)(moduleBase + delayDesc->DllNameRVA),
"steam_api64.dll"))
delayDesc++;
// Load the DLL explicitly, delay import loader is not aware of this relative
// path, then write the module handle to descriptor
const HMODULE steamApiModule =
LoadLibraryW(L"..\\..\\.."
L"\\Engine\\Binaries\\ThirdParty\\Steamworks\\Steamv132\\Win"
L"64\\steam_api64.dll");
*((HMODULE *)(moduleBase + delayDesc->ModuleHandleRVA)) = steamApiModule;
// Initialize Steam API
if (!((bool (*const)())GetProcAddress(steamApiModule, "SteamAPI_Init"))())
ExitProcess(GEC_STEAM_API_INIT_FAILED);
// Step 2: setup Steam interface accessor wrappers
// Get all necessary function addresses
SteamApps = (void *(*)())GetProcAddress(steamApiModule, "SteamApps");
SteamMatchmakingServers =
(void *(*)())GetProcAddress(steamApiModule, "SteamMatchmakingServers");
SteamUGC = (void *(*)())GetProcAddress(steamApiModule, "SteamUGC");
SteamUtils = (void *(*)())GetProcAddress(steamApiModule, "SteamUtils");
// Search import name table for SteamApps
const uint64_t *nameImportsBase =
(const uint64_t *)(moduleBase + delayDesc->ImportNameTableRVA);
uint32_t index = 0;
while (strcmp(
((const IMAGE_IMPORT_BY_NAME *)(moduleBase + nameImportsBase[index]))
->Name,
"SteamApps"))
index++;
// Use the index to get function pointer from IAT and write wrapper address
((void **)(moduleBase + delayDesc->ImportAddressTableRVA))[index] =
SteamApps_wrapper;
// Search import name table for SteamMatchmakingServers
index = 0;
while (strcmp(
((const IMAGE_IMPORT_BY_NAME *)(moduleBase + nameImportsBase[index]))
->Name,
"SteamMatchmakingServers"))