Skip to content

Commit 69430f2

Browse files
committed
Add bypass for Legacy CD Keys
1 parent 0df4308 commit 69430f2

3 files changed

Lines changed: 36 additions & 1 deletion

File tree

src/hooks.cpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,20 @@ static uint32_t hkClientUser_GetSubscribedApps(void* pClientUser, uint32_t* pApp
408408
return count;
409409
}
410410

411+
static bool hkClientUser_RequiresLegacyCDKey(void* pClientUser, uint32_t appId, uint32_t* a2)
412+
{
413+
const bool requiresKey = Hooks::IClientUser_RequiresLegacyCDKey.tramp.fn(pClientUser, appId, a2);
414+
g_pLog->once("IClientUser::RequiresLegacyCDKey(%p, %u, %u) -> %i\n", pClientUser, appId, a2, requiresKey);
415+
416+
if (requiresKey && g_config.isAddedAppId(appId))
417+
{
418+
g_pLog->once("Disable CD Key for %u\n", appId);
419+
return false;
420+
}
421+
422+
return requiresKey;
423+
}
424+
411425
static void patchRetn(lm_address_t address)
412426
{
413427
constexpr lm_byte_t retn = 0xC3;
@@ -504,6 +518,7 @@ namespace Hooks
504518
DetourHook<IClientApps_PipeLoop_t> IClientApps_PipeLoop("IClientApps::PipeLoop");
505519
DetourHook<IClientUser_BIsSubscribedApp_t> IClientUser_BIsSubscribedApp("IClientUser::BIsSubscribedApp");
506520
DetourHook<IClientUser_GetSubscribedApps_t> IClientUser_GetSubscribedApps("IClientUser::GetSubscribedApps");
521+
DetourHook<IClientUser_RequiresLegacyCDKey_t> IClientUser_RequiresLegacyCDKey("IClientUser::RequiresLegacyCDKey");
507522

508523
VFTHook<IClientAppManager_BIsDlcEnabled_t> IClientAppManager_BIsDlcEnabled("IClientAppManager::BIsDlcEnabled");
509524
VFTHook<IClientAppManager_LaunchApp_t> IClientAppManager_LaunchApp("IClientAppManager::LaunchApp");
@@ -535,6 +550,18 @@ bool Hooks::setup()
535550
prologue.size()
536551
);
537552

553+
//TODO: Make this shit less verbose in case I fail my reversing & refactor for all this crap
554+
prologue = std::vector<lm_byte_t>({
555+
0x53, 0x56, 0x57, 0x55
556+
});
557+
bool requiresLegacyCDKey = IClientUser_RequiresLegacyCDKey.setup
558+
(
559+
Patterns::RequiresLegacyCDKey,
560+
MemHlp::SigFollowMode::PrologueUpwards,
561+
&prologue[0],
562+
prologue.size(),
563+
&hkClientUser_RequiresLegacyCDKey
564+
);
538565

539566
bool succeeded =
540567
CheckAppOwnership.setup(Patterns::CheckAppOwnership, MemHlp::SigFollowMode::Relative, &hkCheckAppOwnership)
@@ -546,7 +573,9 @@ bool Hooks::setup()
546573

547574
&& runningApp != LM_ADDRESS_BAD
548575
&& stopPlayingBorrowedApp != LM_ADDRESS_BAD
549-
&& IClientUser_GetSteamId != LM_ADDRESS_BAD;
576+
&& IClientUser_GetSteamId != LM_ADDRESS_BAD
577+
578+
&& requiresLegacyCDKey;
550579

551580
if (!succeeded)
552581
{
@@ -575,6 +604,7 @@ void Hooks::place()
575604
IClientAppManager_PipeLoop.place();
576605
IClientUser_BIsSubscribedApp.place();
577606
IClientUser_GetSubscribedApps.place();
607+
IClientUser_RequiresLegacyCDKey.place();
578608

579609
createAndPlaceSteamIdHook();
580610
}
@@ -588,6 +618,7 @@ void Hooks::remove()
588618
IClientAppManager_PipeLoop.remove();
589619
IClientUser_BIsSubscribedApp.remove();
590620
IClientUser_GetSubscribedApps.remove();
621+
IClientUser_RequiresLegacyCDKey.remove();
591622

592623
//VFT Hooks
593624
IClientAppManager_BIsDlcEnabled.remove();

src/hooks.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,15 @@ namespace Hooks
7272
typedef void(*IClientApps_PipeLoop_t)(void*, void*, void*, void*);
7373
typedef bool(*IClientUser_BIsSubscribedApp_t)(void*, uint32_t);
7474
typedef uint32_t(*IClientUser_GetSubscribedApps_t)(void*, uint32_t*, size_t, bool);
75+
typedef bool(*IClientUser_RequiresLegacyCDKey_t)(void*, uint32_t, uint32_t*);
7576

7677
extern DetourHook<LogSteamPipeCall_t> LogSteamPipeCall;
7778
extern DetourHook<CheckAppOwnership_t> CheckAppOwnership;
7879
extern DetourHook<IClientAppManager_PipeLoop_t> IClientAppManager_PipeLoop;
7980
extern DetourHook<IClientApps_PipeLoop_t> IClientApps_PipeLoop;
8081
extern DetourHook<IClientUser_BIsSubscribedApp_t> IClientUser_BIsSubscribedApp;
8182
extern DetourHook<IClientUser_GetSubscribedApps_t> IClientUser_GetSubscribedApps;
83+
extern DetourHook<IClientUser_RequiresLegacyCDKey_t> IClientUser_RequiresLegacyCDKey;
8284

8385
typedef bool(*IClientAppManager_BIsDlcEnabled_t)(void*, uint32_t, uint32_t, void*);
8486
typedef void*(*IClientAppManager_LaunchApp_t)(void*, uint32_t*, void*, void*, void*);

src/patterns.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ namespace Patterns
2626
constexpr lm_string_t GetSubscribedApps = "E8 ? ? ? ? 89 C6 83 C4 10 85 C0 0F 84 ? ? ? ? 8B 9D ? ? ? ? 39 D8";
2727
//Relative
2828
constexpr lm_string_t IsSubscribedApp = "E8 ? ? ? ? 83 C4 10 84 C0 74 ? 8B 95 ? ? ? ? 83 EC 04";
29+
//End of function
30+
constexpr lm_string_t RequiresLegacyCDKey = "C3 ? ? ? ? ? 8B 44 24 ? 83 C4 1C 89 F9 89 F2 5B 5E 5F 5D 2D 94 18 00 00";
2931
//Relative, not unique. All matches point to correct function though
3032
constexpr lm_string_t GetSteamId = "E8 ? ? ? ? 89 D8 83 C4 0C 83 C4 08 5B C2 04 00 ? 83 EC 08 50 53 FF D2 89 D8 83 C4 0C 83 C4 08 5B C2 04 00";
3133
}

0 commit comments

Comments
 (0)